@wishknish/knishio-client-ts 0.7.6 → 0.7.8
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/README.md +68 -0
- package/dist/index.cjs +305 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -27
- package/dist/index.d.ts +75 -27
- package/dist/index.iife.js +307 -12
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +304 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/KnishIOClient.ts +194 -5
- package/src/core/Molecule.ts +36 -13
- package/src/index.ts +7 -0
- package/src/libraries/GraphQLClient.ts +15 -0
- package/src/query/QueryEmbeddingStatus.ts +130 -0
- package/src/response/ResponseEmbeddingStatus.ts +107 -0
- package/src/response/ResponseProposeMolecule.ts +47 -0
|
@@ -50,6 +50,10 @@ import Response from './Response'
|
|
|
50
50
|
import Dot from '../libraries/Dot'
|
|
51
51
|
import Molecule from '../core/Molecule'
|
|
52
52
|
import type Query from '../query/Query'
|
|
53
|
+
import type BaseException from '../exception/BaseException'
|
|
54
|
+
import MolecularHashMismatchException from '../exception/MolecularHashMismatchException'
|
|
55
|
+
import SignatureMismatchException from '../exception/SignatureMismatchException'
|
|
56
|
+
import AtomIndexException from '../exception/AtomIndexException'
|
|
53
57
|
|
|
54
58
|
/**
|
|
55
59
|
* Response for proposing new Molecules
|
|
@@ -143,6 +147,49 @@ export default class ResponseProposeMolecule extends Response {
|
|
|
143
147
|
return Dot.get(this.data(), 'reason', 'Invalid response from server') as string
|
|
144
148
|
}
|
|
145
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Map this rejection to a typed SDK exception when the failure mode is one
|
|
152
|
+
* we know about. Returns null on success or for rejections we don't have a
|
|
153
|
+
* typed class for.
|
|
154
|
+
*
|
|
155
|
+
* This is the single place pattern-matching against validator reason strings
|
|
156
|
+
* lives — consumers (KnishIOClient cache invalidation, callers needing to
|
|
157
|
+
* branch on failure mode) can `instanceof`-switch on the result instead.
|
|
158
|
+
* Future validator versions can rephrase reasons (or populate a structured
|
|
159
|
+
* field in the response payload) without breaking callers.
|
|
160
|
+
*/
|
|
161
|
+
toException(): BaseException | null {
|
|
162
|
+
if (this.success()) return null
|
|
163
|
+
const reason = this.reason()
|
|
164
|
+
const lc = reason.toLowerCase()
|
|
165
|
+
|
|
166
|
+
if (/molecularhashmismatch|hash.*mismatch/.test(lc)) {
|
|
167
|
+
return new MolecularHashMismatchException(reason, {
|
|
168
|
+
details: { reason },
|
|
169
|
+
code: 'HASH_MISMATCH'
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
if (/ots.*position.*reuse|position.*already.*used|ots.*verification/.test(lc)) {
|
|
173
|
+
return new SignatureMismatchException(reason, {
|
|
174
|
+
details: { reason },
|
|
175
|
+
code: 'OTS_VERIFICATION_FAILED'
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
if (/continuid.*chain|previousposition|chain.*violation/.test(lc)) {
|
|
179
|
+
return new AtomIndexException(reason, {
|
|
180
|
+
details: { reason },
|
|
181
|
+
code: 'INDEX_CONFLICT'
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
if (/signature.*verification|signature.*invalid/.test(lc)) {
|
|
185
|
+
return new SignatureMismatchException(reason, {
|
|
186
|
+
details: { reason },
|
|
187
|
+
code: 'VERIFICATION_FAILED'
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
return null
|
|
191
|
+
}
|
|
192
|
+
|
|
146
193
|
/**
|
|
147
194
|
* Returns payload object
|
|
148
195
|
* Matches JavaScript SDK payload method exactly
|