@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,257 @@
|
|
|
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
|
+
import Meta from './Meta'
|
|
50
|
+
import RuleArgumentException from './exception/RuleArgumentException'
|
|
51
|
+
import { isNumeric } from '@/libraries/strings'
|
|
52
|
+
import { intersect } from '@/libraries/array'
|
|
53
|
+
import { CodeException } from '@/exception'
|
|
54
|
+
import { parseWithSchema } from '@/schemas'
|
|
55
|
+
import type { MetaData, WalletAddress, TokenSlug, MetaType, MetaId } from '@/types'
|
|
56
|
+
import { z } from 'zod'
|
|
57
|
+
|
|
58
|
+
// Define callback action types as a discriminated union
|
|
59
|
+
export type CallbackAction =
|
|
60
|
+
| 'reject'
|
|
61
|
+
| 'meta'
|
|
62
|
+
| 'collect'
|
|
63
|
+
| 'buffer'
|
|
64
|
+
| 'remit'
|
|
65
|
+
| 'burn'
|
|
66
|
+
|
|
67
|
+
// Zod schema for callback validation
|
|
68
|
+
const CallbackParamsSchema = z.object({
|
|
69
|
+
action: z.string().min(1, 'Action cannot be empty'),
|
|
70
|
+
metaType: z.union([z.string(), z.null()]).optional(),
|
|
71
|
+
metaId: z.union([z.string(), z.null()]).optional(),
|
|
72
|
+
meta: z.union([z.instanceof(Meta), z.record(z.unknown()), z.null()]).optional(),
|
|
73
|
+
address: z.union([z.string(), z.null()]).optional(),
|
|
74
|
+
token: z.union([z.string(), z.null()]).optional(),
|
|
75
|
+
amount: z.union([z.string(), z.null()]).optional(),
|
|
76
|
+
comparison: z.union([z.string(), z.null()]).optional()
|
|
77
|
+
}).strict()
|
|
78
|
+
|
|
79
|
+
interface CallbackParams {
|
|
80
|
+
action: CallbackAction | string
|
|
81
|
+
metaType?: MetaType | string | null
|
|
82
|
+
metaId?: MetaId | string | null
|
|
83
|
+
meta?: Meta<MetaData> | MetaData | null
|
|
84
|
+
address?: WalletAddress | string | null
|
|
85
|
+
token?: TokenSlug | string | null
|
|
86
|
+
amount?: string | null
|
|
87
|
+
comparison?: string | null
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface CallbackJSON {
|
|
91
|
+
action: string
|
|
92
|
+
metaType?: string
|
|
93
|
+
metaId?: string
|
|
94
|
+
meta?: MetaData
|
|
95
|
+
address?: string
|
|
96
|
+
token?: string
|
|
97
|
+
amount?: string
|
|
98
|
+
comparison?: string
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Callback class for rule-based actions
|
|
103
|
+
*/
|
|
104
|
+
export default class Callback {
|
|
105
|
+
private __action: string
|
|
106
|
+
private __metaType?: string | null
|
|
107
|
+
private __metaId?: string | null
|
|
108
|
+
private __meta?: Meta | null
|
|
109
|
+
private __address?: string | null
|
|
110
|
+
private __token?: string | null
|
|
111
|
+
private __amount?: string | null
|
|
112
|
+
private __comparison?: string | null
|
|
113
|
+
|
|
114
|
+
constructor(params: CallbackParams) {
|
|
115
|
+
// Validate parameters at runtime
|
|
116
|
+
const validatedParams = parseWithSchema(CallbackParamsSchema, params, 'Callback constructor')
|
|
117
|
+
|
|
118
|
+
if (!validatedParams.action) {
|
|
119
|
+
throw new RuleArgumentException('Callback structure violated, missing mandatory "action" parameter.')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.__action = validatedParams.action
|
|
123
|
+
this.__metaType = validatedParams.metaType ?? null
|
|
124
|
+
this.__metaId = validatedParams.metaId ?? null
|
|
125
|
+
this.__address = validatedParams.address ?? null
|
|
126
|
+
this.__token = validatedParams.token ?? null
|
|
127
|
+
this.__amount = validatedParams.amount ?? null
|
|
128
|
+
this.__comparison = validatedParams.comparison ?? null
|
|
129
|
+
|
|
130
|
+
if (validatedParams.meta) {
|
|
131
|
+
this.__meta = validatedParams.meta instanceof Meta
|
|
132
|
+
? validatedParams.meta
|
|
133
|
+
: Meta.toObject(validatedParams.meta as MetaData)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Setters
|
|
138
|
+
set comparison(comparison: string) {
|
|
139
|
+
this.__comparison = comparison
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
set amount(amount: string) {
|
|
143
|
+
if (!isNumeric(amount)) {
|
|
144
|
+
throw new CodeException('Parameter amount should be a string containing numbers')
|
|
145
|
+
}
|
|
146
|
+
this.__amount = amount
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
set token(token: string) {
|
|
150
|
+
this.__token = token
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
set address(address: string) {
|
|
154
|
+
this.__address = address
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
set meta(meta: Meta<MetaData> | MetaData) {
|
|
158
|
+
this.__meta = meta instanceof Meta ? meta : Meta.toObject(meta)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
set metaType(metaType: string) {
|
|
162
|
+
this.__metaType = metaType
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
set metaId(metaId: string) {
|
|
166
|
+
this.__metaId = metaId
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Creates a Callback from a plain object with validation
|
|
171
|
+
*/
|
|
172
|
+
static toObject(object: CallbackParams): Callback {
|
|
173
|
+
// Use the constructor which already validates the object
|
|
174
|
+
return new Callback(object)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Converts to JSON representation
|
|
179
|
+
*/
|
|
180
|
+
toJSON(): CallbackJSON {
|
|
181
|
+
const meta: CallbackJSON = {
|
|
182
|
+
action: this.__action
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (this.__metaType) {
|
|
186
|
+
meta.metaType = this.__metaType
|
|
187
|
+
}
|
|
188
|
+
if (this.__metaId) {
|
|
189
|
+
meta.metaId = this.__metaId
|
|
190
|
+
}
|
|
191
|
+
if (this.__meta) {
|
|
192
|
+
meta.meta = this.__meta.toJSON()
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (this.__address) {
|
|
196
|
+
meta.address = this.__address
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (this.__token) {
|
|
200
|
+
meta.token = this.__token
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (this.__amount) {
|
|
204
|
+
meta.amount = this.__amount
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (this.__comparison) {
|
|
208
|
+
meta.comparison = this.__comparison
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return meta
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Action type checkers using discriminated unions
|
|
215
|
+
isReject(): this is Callback & { __action: 'reject' } {
|
|
216
|
+
return this._is('reject')
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
isMeta(): this is Callback & { __action: 'meta' } {
|
|
220
|
+
const prop = intersect(Object.keys(this.toJSON()), ['action', 'metaId', 'metaType', 'meta'])
|
|
221
|
+
return prop.length === 4 && this._is('meta')
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
isCollect(): this is Callback & { __action: 'collect' } {
|
|
225
|
+
const prop = intersect(Object.keys(this.toJSON()), ['action', 'address', 'token', 'amount', 'comparison'])
|
|
226
|
+
return prop.length === 5 && this._is('collect')
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
isBuffer(): this is Callback & { __action: 'buffer' } {
|
|
230
|
+
const prop = intersect(Object.keys(this.toJSON()), ['action', 'address', 'token', 'amount', 'comparison'])
|
|
231
|
+
return prop.length === 5 && this._is('buffer')
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
isRemit(): this is Callback & { __action: 'remit' } {
|
|
235
|
+
const prop = intersect(Object.keys(this.toJSON()), ['action', 'token', 'amount'])
|
|
236
|
+
return prop.length === 3 && this._is('remit')
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
isBurn(): this is Callback & { __action: 'burn' } {
|
|
240
|
+
const prop = intersect(Object.keys(this.toJSON()), ['action', 'token', 'amount', 'comparison'])
|
|
241
|
+
return prop.length === 4 && this._is('burn')
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Private helper to check action type with type narrowing
|
|
246
|
+
*/
|
|
247
|
+
private _is(type: CallbackAction): boolean {
|
|
248
|
+
return this.__action.toLowerCase() === type.toLowerCase()
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Type-safe getter for action
|
|
253
|
+
*/
|
|
254
|
+
get action(): string {
|
|
255
|
+
return this.__action
|
|
256
|
+
}
|
|
257
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
import RuleArgumentException from './exception/RuleArgumentException'
|
|
50
|
+
|
|
51
|
+
interface ConditionParams {
|
|
52
|
+
key: string
|
|
53
|
+
value: any
|
|
54
|
+
comparison: string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Condition class for rule-based logic
|
|
59
|
+
*/
|
|
60
|
+
export default class Condition {
|
|
61
|
+
private __key: string
|
|
62
|
+
private __value: any
|
|
63
|
+
private __comparison: string
|
|
64
|
+
|
|
65
|
+
constructor({ key, value, comparison }: ConditionParams) {
|
|
66
|
+
if ([key, value, comparison].some(item => !item)) {
|
|
67
|
+
throw new RuleArgumentException('Condition::constructor( { key, value, comparison } ) - not all class parameters are initialised!')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.__key = key
|
|
71
|
+
this.__value = value
|
|
72
|
+
this.__comparison = comparison
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Creates a Condition from a plain object
|
|
77
|
+
*/
|
|
78
|
+
static toObject(object: ConditionParams): Condition {
|
|
79
|
+
return new this({
|
|
80
|
+
key: object.key,
|
|
81
|
+
value: object.value,
|
|
82
|
+
comparison: object.comparison
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Converts to JSON representation
|
|
88
|
+
*/
|
|
89
|
+
toJSON(): ConditionParams {
|
|
90
|
+
return {
|
|
91
|
+
key: this.__key,
|
|
92
|
+
value: this.__value,
|
|
93
|
+
comparison: this.__comparison
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
import { MetaDataSchema, parseWithSchema } from '@/schemas'
|
|
50
|
+
import type { MetaData } from '@/types'
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Meta class for handling dynamic metadata objects with type safety
|
|
54
|
+
*
|
|
55
|
+
* Uses TypeScript 2025 patterns with proper generics and runtime validation
|
|
56
|
+
*/
|
|
57
|
+
export default class Meta<T extends MetaData = MetaData> {
|
|
58
|
+
private readonly __data: Map<string, T[keyof T]> = new Map()
|
|
59
|
+
|
|
60
|
+
constructor(args: T = {} as T) {
|
|
61
|
+
// Validate input at runtime using Zod
|
|
62
|
+
const validatedArgs = parseWithSchema(MetaDataSchema, args, 'Meta constructor')
|
|
63
|
+
|
|
64
|
+
// Store validated data
|
|
65
|
+
for (const [key, value] of Object.entries(validatedArgs)) {
|
|
66
|
+
this.__data.set(`__${key}`, value)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Creates a Meta object from a plain object with runtime validation
|
|
72
|
+
*/
|
|
73
|
+
static toObject<U extends MetaData>(object: U): Meta<U> {
|
|
74
|
+
return new Meta(object)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Gets a metadata value by key
|
|
79
|
+
*/
|
|
80
|
+
get<K extends keyof T>(key: K): T[K] | undefined {
|
|
81
|
+
return this.__data.get(`__${String(key)}`) as T[K] | undefined
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Sets a metadata value by key
|
|
86
|
+
*/
|
|
87
|
+
set<K extends keyof T>(key: K, value: T[K]): void {
|
|
88
|
+
this.__data.set(`__${String(key)}`, value)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Checks if a key exists
|
|
93
|
+
*/
|
|
94
|
+
has<K extends keyof T>(key: K): boolean {
|
|
95
|
+
return this.__data.has(`__${String(key)}`)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Gets all keys
|
|
100
|
+
*/
|
|
101
|
+
keys(): string[] {
|
|
102
|
+
return Array.from(this.__data.keys()).map(key =>
|
|
103
|
+
key.startsWith('__') ? key.substring(2) : key
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Converts Meta object back to plain object
|
|
109
|
+
*/
|
|
110
|
+
toJSON(): T {
|
|
111
|
+
const object = {} as Record<string, T[keyof T]>
|
|
112
|
+
|
|
113
|
+
for (const [key, value] of this.__data.entries()) {
|
|
114
|
+
if (key.startsWith('__')) {
|
|
115
|
+
const plainKey = key.substring(2)
|
|
116
|
+
object[plainKey] = value
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return object as unknown as T
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Creates a typed copy of this Meta object
|
|
125
|
+
*/
|
|
126
|
+
clone(): Meta<T> {
|
|
127
|
+
return new Meta(this.toJSON())
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Merges another Meta object into this one
|
|
132
|
+
*/
|
|
133
|
+
merge<U extends MetaData>(other: Meta<U>): Meta<T & U> {
|
|
134
|
+
const combined = { ...this.toJSON(), ...other.toJSON() }
|
|
135
|
+
return new Meta(combined)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Type-safe iteration over metadata entries
|
|
140
|
+
*/
|
|
141
|
+
forEach<K extends keyof T>(callback: (value: T[K], key: K) => void): void {
|
|
142
|
+
for (const [key, value] of this.__data.entries()) {
|
|
143
|
+
if (key.startsWith('__')) {
|
|
144
|
+
const plainKey = key.substring(2) as K
|
|
145
|
+
callback(value as T[K], plainKey)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Returns the size of the metadata object
|
|
152
|
+
*/
|
|
153
|
+
get size(): number {
|
|
154
|
+
return this.__data.size
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Clears all metadata
|
|
159
|
+
*/
|
|
160
|
+
clear(): void {
|
|
161
|
+
this.__data.clear()
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule class - Policy and rule management for KnishIO DLT
|
|
3
|
+
* STUB IMPLEMENTATION - Full implementation pending
|
|
4
|
+
*/
|
|
5
|
+
export default class Rule {
|
|
6
|
+
public name: string
|
|
7
|
+
public conditions: any[]
|
|
8
|
+
public actions: any[]
|
|
9
|
+
|
|
10
|
+
constructor(data: any = {}) {
|
|
11
|
+
this.name = data.name || ''
|
|
12
|
+
this.conditions = data.conditions || []
|
|
13
|
+
this.actions = data.actions || []
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Convert rule data to Rule object
|
|
18
|
+
* @param data - Rule data to convert
|
|
19
|
+
* @return Rule instance
|
|
20
|
+
*/
|
|
21
|
+
static toObject(data: any): Rule {
|
|
22
|
+
if (data instanceof Rule) {
|
|
23
|
+
return data
|
|
24
|
+
}
|
|
25
|
+
return new Rule(data)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// TODO: Implement remaining Rule methods
|
|
29
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
import BaseException from '@/exception/BaseException'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Thrown when rule arguments are invalid or missing
|
|
53
|
+
*/
|
|
54
|
+
export class RuleArgumentException extends BaseException {
|
|
55
|
+
/**
|
|
56
|
+
* Constructor
|
|
57
|
+
*/
|
|
58
|
+
constructor(
|
|
59
|
+
message: string = 'An incorrect argument!'
|
|
60
|
+
) {
|
|
61
|
+
super('RULE_ARGUMENT_ERROR', message)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default RuleArgumentException
|