@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.
Files changed (141) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +425 -0
  3. package/dist/index.cjs +9961 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.iife.js +32241 -0
  6. package/dist/index.iife.js.map +1 -0
  7. package/dist/index.js +9853 -0
  8. package/dist/index.js.map +1 -0
  9. package/package.json +113 -0
  10. package/src/AuthToken.ts +214 -0
  11. package/src/KnishIOClient.ts +2020 -0
  12. package/src/constants.ts +398 -0
  13. package/src/core/Atom.ts +646 -0
  14. package/src/core/AtomMeta.ts +278 -0
  15. package/src/core/Meta.ts +428 -0
  16. package/src/core/Molecule.ts +825 -0
  17. package/src/core/PolicyMeta.ts +130 -0
  18. package/src/core/TokenUnit.ts +148 -0
  19. package/src/core/Wallet.ts +467 -0
  20. package/src/exception/AtomIndexException.ts +97 -0
  21. package/src/exception/AtomsMissingException.ts +109 -0
  22. package/src/exception/AuthorizationRejectedException.ts +63 -0
  23. package/src/exception/BalanceInsufficientException.ts +58 -0
  24. package/src/exception/BaseException.ts +275 -0
  25. package/src/exception/BatchIdException.ts +58 -0
  26. package/src/exception/CodeException.ts +119 -0
  27. package/src/exception/DecryptionKeyException.ts +65 -0
  28. package/src/exception/InvalidResponseException.ts +112 -0
  29. package/src/exception/MetaMissingException.ts +58 -0
  30. package/src/exception/MolecularHashMismatchException.ts +115 -0
  31. package/src/exception/MolecularHashMissingException.ts +58 -0
  32. package/src/exception/NegativeAmountException.ts +58 -0
  33. package/src/exception/PolicyInvalidException.ts +58 -0
  34. package/src/exception/SignatureMalformedException.ts +58 -0
  35. package/src/exception/SignatureMismatchException.ts +98 -0
  36. package/src/exception/StackableUnitAmountException.ts +65 -0
  37. package/src/exception/StackableUnitDecimalsException.ts +65 -0
  38. package/src/exception/TransferBalanceException.ts +98 -0
  39. package/src/exception/TransferMalformedException.ts +58 -0
  40. package/src/exception/TransferMismatchedException.ts +58 -0
  41. package/src/exception/TransferRemainderException.ts +58 -0
  42. package/src/exception/TransferToSelfException.ts +58 -0
  43. package/src/exception/TransferUnbalancedException.ts +58 -0
  44. package/src/exception/UnauthenticatedException.ts +147 -0
  45. package/src/exception/WalletCredentialException.ts +108 -0
  46. package/src/exception/WalletShadowException.ts +65 -0
  47. package/src/exception/WrongTokenTypeException.ts +58 -0
  48. package/src/exception/index.ts +272 -0
  49. package/src/index.ts +512 -0
  50. package/src/instance/rules/Callback.ts +257 -0
  51. package/src/instance/rules/Condition.ts +96 -0
  52. package/src/instance/rules/Meta.ts +163 -0
  53. package/src/instance/rules/Rule.ts +29 -0
  54. package/src/instance/rules/exception/RuleArgumentException.ts +65 -0
  55. package/src/libraries/CheckMolecule.ts +581 -0
  56. package/src/libraries/Decimal.ts +94 -0
  57. package/src/libraries/Dot.ts +202 -0
  58. package/src/libraries/GraphQLClient.ts +276 -0
  59. package/src/libraries/Hex.ts +155 -0
  60. package/src/libraries/UrqlClientWrapper.ts +336 -0
  61. package/src/libraries/array.ts +91 -0
  62. package/src/libraries/crypto.ts +816 -0
  63. package/src/libraries/strings.ts +458 -0
  64. package/src/mutation/Mutation.ts +103 -0
  65. package/src/mutation/MutationActiveSession.ts +108 -0
  66. package/src/mutation/MutationClaimShadowWallet.ts +91 -0
  67. package/src/mutation/MutationCreateIdentifier.ts +86 -0
  68. package/src/mutation/MutationCreateMeta.ts +92 -0
  69. package/src/mutation/MutationCreateRule.ts +90 -0
  70. package/src/mutation/MutationCreateToken.ts +92 -0
  71. package/src/mutation/MutationCreateWallet.ts +78 -0
  72. package/src/mutation/MutationDepositBufferToken.ts +72 -0
  73. package/src/mutation/MutationLinkIdentifier.ts +87 -0
  74. package/src/mutation/MutationProposeMolecule.ts +147 -0
  75. package/src/mutation/MutationRequestAuthorization.ts +77 -0
  76. package/src/mutation/MutationRequestAuthorizationGuest.ts +85 -0
  77. package/src/mutation/MutationRequestTokens.ts +98 -0
  78. package/src/mutation/MutationTransferTokens.ts +87 -0
  79. package/src/mutation/MutationWithdrawBufferToken.ts +73 -0
  80. package/src/query/Query.ts +187 -0
  81. package/src/query/QueryActiveSession.ts +89 -0
  82. package/src/query/QueryAtom.ts +275 -0
  83. package/src/query/QueryBalance.ts +102 -0
  84. package/src/query/QueryBatch.ts +145 -0
  85. package/src/query/QueryBatchHistory.ts +86 -0
  86. package/src/query/QueryContinuId.ts +91 -0
  87. package/src/query/QueryMetaType.ts +177 -0
  88. package/src/query/QueryMetaTypeViaAtom.ts +199 -0
  89. package/src/query/QueryPolicy.ts +91 -0
  90. package/src/query/QueryToken.ts +90 -0
  91. package/src/query/QueryUserActivity.ts +153 -0
  92. package/src/query/QueryWalletBundle.ts +92 -0
  93. package/src/query/QueryWalletList.ts +106 -0
  94. package/src/response/EnhancedResponse.ts +345 -0
  95. package/src/response/Response.ts +254 -0
  96. package/src/response/ResponseActiveSession.ts +72 -0
  97. package/src/response/ResponseAtom.ts +132 -0
  98. package/src/response/ResponseAuthorizationGuest.ts +119 -0
  99. package/src/response/ResponseBalance.ts +153 -0
  100. package/src/response/ResponseClaimShadowWallet.ts +56 -0
  101. package/src/response/ResponseContinuId.ts +101 -0
  102. package/src/response/ResponseCreateIdentifier.ts +56 -0
  103. package/src/response/ResponseCreateMeta.ts +58 -0
  104. package/src/response/ResponseCreateRule.ts +56 -0
  105. package/src/response/ResponseCreateToken.ts +58 -0
  106. package/src/response/ResponseCreateWallet.ts +58 -0
  107. package/src/response/ResponseLinkIdentifier.ts +87 -0
  108. package/src/response/ResponseMetaBatch.ts +72 -0
  109. package/src/response/ResponseMetaType.ts +108 -0
  110. package/src/response/ResponseMetaTypeViaAtom.ts +108 -0
  111. package/src/response/ResponsePolicy.ts +90 -0
  112. package/src/response/ResponseProposeMolecule.ts +155 -0
  113. package/src/response/ResponseQueryActiveSession.ts +105 -0
  114. package/src/response/ResponseQueryUserActivity.ts +89 -0
  115. package/src/response/ResponseRequestAuthorization.ts +100 -0
  116. package/src/response/ResponseRequestAuthorizationGuest.ts +133 -0
  117. package/src/response/ResponseRequestTokens.ts +58 -0
  118. package/src/response/ResponseTransferTokens.ts +72 -0
  119. package/src/response/ResponseWalletBundle.ts +95 -0
  120. package/src/response/ResponseWalletList.ts +165 -0
  121. package/src/schemas/index.ts +457 -0
  122. package/src/subscribe/ActiveSessionSubscribe.ts +72 -0
  123. package/src/subscribe/ActiveWalletSubscribe.ts +99 -0
  124. package/src/subscribe/CreateMoleculeSubscribe.ts +106 -0
  125. package/src/subscribe/Subscribe.ts +182 -0
  126. package/src/subscribe/WalletStatusSubscribe.ts +70 -0
  127. package/src/subscribe/index.ts +59 -0
  128. package/src/types/assertions.ts +722 -0
  129. package/src/types/client.ts +567 -0
  130. package/src/types/crypto.ts +541 -0
  131. package/src/types/graphql.ts +630 -0
  132. package/src/types/guards.ts +659 -0
  133. package/src/types/index.ts +614 -0
  134. package/src/types/response.ts +133 -0
  135. package/src/types/template-literals.ts +382 -0
  136. package/src/validation/UNIVERSAL_CONFIGURATION_INTERFACES.ts +580 -0
  137. package/src/validation/ValidationService.ts +607 -0
  138. package/src/validation/schemas.ts +447 -0
  139. package/src/versions/HashAtom.ts +170 -0
  140. package/src/versions/Version4.ts +120 -0
  141. package/src/versions/index.ts +80 -0
@@ -0,0 +1,133 @@
1
+ /*
2
+ Enhanced Response Types for TypeScript SDK Gold Standard
3
+
4
+ Implements comprehensive response interface with ValidationResult patterns,
5
+ enhanced error handling, and functional programming support.
6
+ */
7
+
8
+ import { z } from 'zod'
9
+
10
+ // Universal response interface matching JavaScript SDK pattern
11
+ export interface UniversalResponse<T> {
12
+ success(): boolean // Operation success status
13
+ payload(): T | null // Result data (typed)
14
+ reason(): string | null // Error message/reason
15
+ data(): any // Raw response data access
16
+ }
17
+
18
+ // Enhanced validation result pattern for TypeScript gold standard
19
+ export interface ValidationResult<T> {
20
+ success: boolean
21
+ data?: T
22
+ error?: {
23
+ message: string
24
+ details?: string[]
25
+ code?: string
26
+ context?: Record<string, any>
27
+ }
28
+ warnings?: string[]
29
+ }
30
+
31
+ // Enhanced error information with detailed context
32
+ export interface ResponseError {
33
+ message: string
34
+ code?: string
35
+ details?: any
36
+ context?: string
37
+ timestamp?: string
38
+ operation?: string
39
+ }
40
+
41
+ // Response validation schemas for runtime type checking
42
+ export const ResponseErrorSchema = z.object({
43
+ message: z.string(),
44
+ code: z.string().optional(),
45
+ details: z.any().optional(),
46
+ context: z.string().optional(),
47
+ timestamp: z.string().optional(),
48
+ operation: z.string().optional()
49
+ })
50
+
51
+ export const ValidationResultSchema = z.object({
52
+ success: z.boolean(),
53
+ data: z.any().optional(),
54
+ error: ResponseErrorSchema.optional(),
55
+ warnings: z.array(z.string()).optional()
56
+ })
57
+
58
+ // Enhanced response interface with functional programming support
59
+ export interface EnhancedResponse<T> extends UniversalResponse<T> {
60
+ // Validation result conversion
61
+ toValidationResult(): ValidationResult<T>
62
+
63
+ // Functional programming combinators
64
+ map<U>(mapper: (value: T) => U): EnhancedResponse<U>
65
+ flatMap<U>(mapper: (value: T) => EnhancedResponse<U>): EnhancedResponse<U>
66
+ filter(predicate: (value: T) => boolean): EnhancedResponse<T>
67
+
68
+ // Error handling enhancements
69
+ onSuccess(callback: (payload: T) => void): EnhancedResponse<T>
70
+ onFailure(callback: (error: string) => void): EnhancedResponse<T>
71
+
72
+ // Promise integration
73
+ toPromise(): Promise<T>
74
+
75
+ // Enhanced debugging
76
+ debug(label?: string): EnhancedResponse<T>
77
+ }
78
+
79
+ // Configuration validation result for enhanced type safety
80
+ export interface ConfigValidationResult<T> extends ValidationResult<T> {
81
+ originalConfig?: Record<string, any>
82
+ validatedConfig?: T
83
+ validationErrors?: Array<{
84
+ field: string
85
+ message: string
86
+ received: any
87
+ expected: string
88
+ }>
89
+ }
90
+
91
+ // Response metadata for enhanced debugging and monitoring
92
+ export interface ResponseMetadata {
93
+ timestamp: string
94
+ operation: string
95
+ duration?: number
96
+ requestId?: string
97
+ serverVersion?: string
98
+ clientVersion: string
99
+ }
100
+
101
+ // Enhanced response type with comprehensive metadata
102
+ export interface StandardResponseWithMetadata<T> extends EnhancedResponse<T> {
103
+ metadata(): ResponseMetadata
104
+ correlationId(): string | null
105
+ duration(): number | null
106
+ }
107
+
108
+ // Factory functions for consistent response creation
109
+ export interface ResponseFactory {
110
+ success<T>(payload: T, metadata?: ResponseMetadata): EnhancedResponse<T>
111
+ failure<T>(error: string | ResponseError, metadata?: ResponseMetadata): EnhancedResponse<T>
112
+ fromValidationResult<T>(result: ValidationResult<T>, metadata?: ResponseMetadata): EnhancedResponse<T>
113
+ }
114
+
115
+ // Type guards for response type checking
116
+ export function isSuccessResponse<T>(response: EnhancedResponse<T>): response is EnhancedResponse<T> & { payload(): T } {
117
+ return response.success() && response.payload() !== null
118
+ }
119
+
120
+ export function isErrorResponse<T>(response: EnhancedResponse<T>): response is EnhancedResponse<T> & { reason(): string } {
121
+ return !response.success() && response.reason() !== null
122
+ }
123
+
124
+ // Enhanced response union type for comprehensive type checking
125
+ export type ResponseResult<T> = EnhancedResponse<T> | ValidationResult<T>
126
+
127
+ // Export specific response types
128
+ export type MetaResponse = EnhancedResponse<any>
129
+ export type TokenResponse = EnhancedResponse<any>
130
+ export type TransferResponse = EnhancedResponse<any>
131
+ export type BalanceResponse = EnhancedResponse<any>
132
+ export type WalletResponse = EnhancedResponse<any>
133
+ export type AuthResponse = EnhancedResponse<any>
@@ -0,0 +1,382 @@
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
+ * Template Literal Type Definitions for KnishIO SDK
51
+ *
52
+ * Implements 2025 TypeScript patterns:
53
+ * - Advanced template literal types for validation
54
+ * - Pattern-based type safety for APIs
55
+ * - Const assertion integration
56
+ */
57
+
58
+ import type {
59
+ AtomIsotope,
60
+ QueryType,
61
+ MutationType,
62
+ SubscriptionType,
63
+ KnishIOErrorType
64
+ } from '../constants'
65
+
66
+ // =============================================================================
67
+ // GRAPHQL TEMPLATE LITERAL TYPES
68
+ // =============================================================================
69
+
70
+ /**
71
+ * GraphQL operation name template literals
72
+ */
73
+ export type QueryOperationName<T extends QueryType> = `Query${T}`
74
+ export type MutationOperationName<T extends MutationType> = `Mutation${T}`
75
+ export type SubscriptionOperationName<T extends SubscriptionType> = `Subscribe${T}`
76
+
77
+ /**
78
+ * GraphQL field selection template literals
79
+ */
80
+ export type FieldSelection<T extends string> = `${T} { ${string} }`
81
+ export type NestedFieldSelection<T extends string, U extends string> = `${T} { ${U} { ${string} } }`
82
+
83
+ /**
84
+ * GraphQL variable templates
85
+ */
86
+ export type GraphQLVariable<T extends string> = `$${T}`
87
+ export type GraphQLVariableDeclaration<T extends string, U extends string> = `${GraphQLVariable<T>}: ${U}`
88
+
89
+ /**
90
+ * Complete GraphQL operation templates
91
+ */
92
+ export type GraphQLQuery<T extends string> = `query ${T}(${string}) { ${string} }`
93
+ export type GraphQLMutation<T extends string> = `mutation ${T}(${string}) { ${string} }`
94
+ export type GraphQLSubscription<T extends string> = `subscription ${T}(${string}) { ${string} }`
95
+
96
+ // =============================================================================
97
+ // API ENDPOINT TEMPLATE LITERALS
98
+ // =============================================================================
99
+
100
+ /**
101
+ * REST API endpoint patterns
102
+ */
103
+ export type APIEndpoint<T extends string> = `/api/${T}`
104
+ export type VersionedEndpoint<V extends string, T extends string> = `/api/${V}/${T}`
105
+ export type ResourceEndpoint<T extends string> = APIEndpoint<`${T}s`>
106
+ export type ResourceByIdEndpoint<T extends string, ID extends string> = APIEndpoint<`${T}s/${ID}`>
107
+
108
+ /**
109
+ * KnishIO specific endpoint patterns
110
+ */
111
+ export type KnishIOEndpoint<T extends string> = `/knishio/${T}`
112
+ export type CellEndpoint<C extends string, T extends string> = KnishIOEndpoint<`cells/${C}/${T}`>
113
+ export type WalletEndpoint<W extends string> = KnishIOEndpoint<`wallets/${W}`>
114
+ export type AtomEndpoint<A extends string> = KnishIOEndpoint<`atoms/${A}`>
115
+ export type MoleculeEndpoint<M extends string> = KnishIOEndpoint<`molecules/${M}`>
116
+
117
+ // =============================================================================
118
+ // ERROR MESSAGE TEMPLATE LITERALS
119
+ // =============================================================================
120
+
121
+ /**
122
+ * Error message construction templates
123
+ */
124
+ export type ErrorMessage<T extends KnishIOErrorType> = `${T}: ${string}`
125
+ export type DetailedErrorMessage<T extends KnishIOErrorType, D extends string> = `${T}: ${D}`
126
+ export type FieldValidationError<F extends string> = `Validation failed for field '${F}'`
127
+ export type OperationError<O extends string> = `Operation '${O}' failed`
128
+ export type NetworkError<E extends string> = `Network error: ${E}`
129
+
130
+ /**
131
+ * Specific error templates for common cases
132
+ */
133
+ export type WalletError<W extends string> = `Wallet error for ${W}`
134
+ export type AtomError<A extends AtomIsotope> = `Atom error for isotope ${A}`
135
+ export type MoleculeError<M extends string> = `Molecule error: ${M}`
136
+ export type AuthError<A extends string> = `Authentication error: ${A}`
137
+ export type ValidationError<F extends string, V extends string> = `Validation failed for ${F}: expected ${V}`
138
+
139
+ // =============================================================================
140
+ // CONFIGURATION TEMPLATE LITERALS
141
+ // =============================================================================
142
+
143
+ /**
144
+ * Environment variable patterns
145
+ */
146
+ export type EnvVar<T extends string> = `${Uppercase<T>}`
147
+ export type KnishIOEnvVar<T extends string> = EnvVar<`KNISHIO_${T}`>
148
+ export type NodeEnvVar<T extends string> = EnvVar<`NODE_${T}`>
149
+
150
+ /**
151
+ * Configuration key patterns
152
+ */
153
+ export type ConfigKey<T extends string> = `${Lowercase<T>}`
154
+ export type NestedConfigKey<P extends string, K extends string> = `${ConfigKey<P>}.${ConfigKey<K>}`
155
+
156
+ /**
157
+ * URL and URI template patterns
158
+ */
159
+ export type Protocol = 'http' | 'https' | 'ws' | 'wss'
160
+ export type URLWithProtocol<P extends Protocol, H extends string> = `${P}://${H}`
161
+ export type GraphQLEndpoint<H extends string> = URLWithProtocol<'https', `${H}/graphql`>
162
+ export type WebSocketEndpoint<H extends string> = URLWithProtocol<'wss', `${H}/ws`>
163
+
164
+ // =============================================================================
165
+ // ISOTOPE-SPECIFIC TEMPLATE LITERALS
166
+ // =============================================================================
167
+
168
+ /**
169
+ * Isotope operation patterns
170
+ */
171
+ export type IsotopeOperation<I extends AtomIsotope, O extends string> = `${I}_${Uppercase<O>}`
172
+ export type IsotopeValidation<I extends AtomIsotope> = `validate_${Lowercase<I>}_isotope`
173
+ export type IsotopeHandler<I extends AtomIsotope> = `handle${Capitalize<Lowercase<I>>}Isotope`
174
+
175
+ /**
176
+ * Specific isotope patterns
177
+ */
178
+ export type ValueOperation<O extends string> = IsotopeOperation<'V', O>
179
+ export type MetaOperation<O extends string> = IsotopeOperation<'M', O>
180
+ export type ContinueOperation<O extends string> = IsotopeOperation<'C', O>
181
+ export type TokenOperation<O extends string> = IsotopeOperation<'T', O>
182
+
183
+ // =============================================================================
184
+ // WALLET AND ADDRESS TEMPLATE LITERALS
185
+ // =============================================================================
186
+
187
+ /**
188
+ * Wallet identifier patterns
189
+ */
190
+ export type WalletPrefix = 'wallet'
191
+ export type WalletId<ID extends string> = `${WalletPrefix}_${ID}`
192
+ export type WalletAddress<A extends string> = `addr_${A}`
193
+ export type BundleRef<B extends string> = `bundle_${B}`
194
+
195
+ /**
196
+ * Position and molecular patterns
197
+ */
198
+ export type PositionRef<P extends string> = `pos_${P}`
199
+ export type MolecularRef<M extends string> = `mol_${M}`
200
+ export type AtomRef<A extends string> = `atom_${A}`
201
+
202
+ // =============================================================================
203
+ // QUERY AND FILTER TEMPLATE LITERALS
204
+ // =============================================================================
205
+
206
+ /**
207
+ * Filter expression patterns
208
+ */
209
+ export type FilterExpression<F extends string, O extends string, V extends string> = `${F} ${O} ${V}`
210
+ export type EqualsFilter<F extends string, V extends string> = FilterExpression<F, '=', V>
211
+ export type ContainsFilter<F extends string, V extends string> = FilterExpression<F, 'CONTAINS', V>
212
+ export type GreaterThanFilter<F extends string, V extends string> = FilterExpression<F, '>', V>
213
+
214
+ /**
215
+ * Sort expression patterns
216
+ */
217
+ export type SortDirection = 'ASC' | 'DESC'
218
+ export type SortExpression<F extends string, D extends SortDirection> = `${F} ${D}`
219
+ export type OrderByExpression<F extends string> = `ORDER BY ${F}`
220
+
221
+ /**
222
+ * Query builder patterns
223
+ */
224
+ export type SelectClause<F extends string> = `SELECT ${F}`
225
+ export type FromClause<T extends string> = `FROM ${T}`
226
+ export type WhereClause<C extends string> = `WHERE ${C}`
227
+ export type LimitClause<L extends number> = `LIMIT ${L}`
228
+
229
+ // =============================================================================
230
+ // VALIDATION PATTERN TEMPLATE LITERALS
231
+ // =============================================================================
232
+
233
+ /**
234
+ * Validation rule patterns
235
+ */
236
+ export type ValidationRule<T extends string> = `validate_${T}`
237
+ export type RequiredValidation<F extends string> = `${F}_required`
238
+ export type LengthValidation<F extends string, Min extends number, Max extends number> = `${F}_length_${Min}_${Max}`
239
+ export type PatternValidation<F extends string, P extends string> = `${F}_pattern_${P}`
240
+
241
+ /**
242
+ * Type checking patterns
243
+ */
244
+ export type TypeCheck<T extends string> = `is_${T}`
245
+ export type ArrayTypeCheck<T extends string> = `is_array_of_${T}`
246
+ export type ObjectTypeCheck<T extends string> = `is_object_with_${T}`
247
+
248
+ // =============================================================================
249
+ // CRYPTO AND HASH TEMPLATE LITERALS
250
+ // =============================================================================
251
+
252
+ /**
253
+ * Hash algorithm patterns
254
+ */
255
+ export type HashAlgorithm = 'sha256' | 'sha3_256' | 'blake2b' | 'shake256'
256
+ export type HashFunction<A extends HashAlgorithm> = `hash_${A}`
257
+ export type HashResult<A extends HashAlgorithm, L extends number> = `${A}_${L}_${string}`
258
+
259
+ /**
260
+ * Signature patterns
261
+ */
262
+ export type SignatureAlgorithm = 'ed25519' | 'secp256k1' | 'xmss'
263
+ export type SignatureFunction<A extends SignatureAlgorithm> = `sign_${A}`
264
+ export type VerifyFunction<A extends SignatureAlgorithm> = `verify_${A}`
265
+
266
+ /**
267
+ * Key patterns
268
+ */
269
+ export type KeyType = 'private' | 'public'
270
+ export type KeyFormat = 'hex' | 'base64' | 'pem'
271
+ export type KeyIdentifier<T extends KeyType, F extends KeyFormat> = `${T}_key_${F}`
272
+
273
+ // =============================================================================
274
+ // EVENT AND CALLBACK TEMPLATE LITERALS
275
+ // =============================================================================
276
+
277
+ /**
278
+ * Event name patterns
279
+ */
280
+ export type EventName<T extends string> = `on${Capitalize<T>}`
281
+ export type EventHandler<T extends string> = `handle${Capitalize<T>}`
282
+ export type EventListener<T extends string> = `${T}Listener`
283
+
284
+ /**
285
+ * Callback patterns
286
+ */
287
+ export type CallbackName<T extends string> = `${T}Callback`
288
+ export type SuccessCallback<T extends string> = `on${Capitalize<T>}Success`
289
+ export type ErrorCallback<T extends string> = `on${Capitalize<T>}Error`
290
+
291
+ /**
292
+ * Lifecycle patterns
293
+ */
294
+ export type LifecycleEvent<T extends string> = `on${Capitalize<T>}`
295
+ export type BeforeEvent<T extends string> = `before${Capitalize<T>}`
296
+ export type AfterEvent<T extends string> = `after${Capitalize<T>}`
297
+
298
+ // =============================================================================
299
+ // UTILITY TEMPLATE LITERAL HELPERS
300
+ // =============================================================================
301
+
302
+ /**
303
+ * String manipulation templates
304
+ */
305
+ export type CamelCase<S extends string> = S extends `${infer A}_${infer B}`
306
+ ? `${Lowercase<A>}${Capitalize<CamelCase<B>>}`
307
+ : Lowercase<S>
308
+
309
+ export type PascalCase<S extends string> = Capitalize<CamelCase<S>>
310
+
311
+ export type SnakeCase<S extends string> = S extends `${infer A}${infer B}`
312
+ ? A extends Lowercase<A>
313
+ ? `${A}${SnakeCase<B>}`
314
+ : `_${Lowercase<A>}${SnakeCase<B>}`
315
+ : S
316
+
317
+ export type KebabCase<S extends string> = S extends `${infer A}${infer B}`
318
+ ? A extends Lowercase<A>
319
+ ? `${A}${KebabCase<B>}`
320
+ : `-${Lowercase<A>}${KebabCase<B>}`
321
+ : S
322
+
323
+ /**
324
+ * Path manipulation templates
325
+ */
326
+ export type JoinPath<A extends string, B extends string> = `${A}/${B}`
327
+ export type DeepPath<T extends readonly string[]> = T extends readonly [infer First, ...infer Rest]
328
+ ? First extends string
329
+ ? Rest extends readonly string[]
330
+ ? Rest['length'] extends 0
331
+ ? First
332
+ : `${First}.${DeepPath<Rest>}`
333
+ : never
334
+ : never
335
+ : never
336
+
337
+ /**
338
+ * Template literal type guards
339
+ */
340
+ export type IsTemplate<T> = T extends `${string}` ? true : false
341
+ export type TemplateLength<T extends string> = T['length']
342
+ export type TemplateStartsWith<T extends string, P extends string> = T extends `${P}${string}` ? true : false
343
+ export type TemplateEndsWith<T extends string, S extends string> = T extends `${string}${S}` ? true : false
344
+
345
+ // =============================================================================
346
+ // CONST ASSERTION HELPERS FOR TEMPLATE LITERALS
347
+ // =============================================================================
348
+
349
+ /**
350
+ * Create template literal patterns with const assertions
351
+ */
352
+ export function createTemplate<T extends string>(template: T): T {
353
+ return template
354
+ }
355
+
356
+ /**
357
+ * Template literal builder with const assertions
358
+ */
359
+ export class TemplateBuilder<T extends string = ''> {
360
+ constructor(private readonly value: T) {}
361
+
362
+ append<U extends string>(suffix: U): TemplateBuilder<`${T}${U}`> {
363
+ return new TemplateBuilder(`${this.value}${suffix}` as const)
364
+ }
365
+
366
+ prepend<U extends string>(prefix: U): TemplateBuilder<`${U}${T}`> {
367
+ return new TemplateBuilder(`${prefix}${this.value}` as const)
368
+ }
369
+
370
+ build(): T {
371
+ return this.value
372
+ }
373
+ }
374
+
375
+ /**
376
+ * Factory function for template builder
377
+ */
378
+ export function template<T extends string>(initial: T = '' as T): TemplateBuilder<T> {
379
+ return new TemplateBuilder(initial)
380
+ }
381
+
382
+ // All types are already exported at their definitions above