MCPcopy Index your code
hub / github.com/1Panel-dev/MaxKB / parseAndValidate

Function parseAndValidate

ui/src/workflow/common/shortcut.ts:252–289  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

250 }
251
252 const parseAndValidate = (text: string) => {
253 let data: any
254 try {
255 data = JSON.parse(text)
256 } catch {
257 throw new Error('数据不是合法的 JSON')
258 }
259
260 if (!data || typeof data !== 'object' || Array.isArray(data)) {
261 throw new Error('数据必须是对象')
262 }
263
264 if (!('nodes' in data)) {
265 throw new Error('数据缺少 nodes 字段')
266 }
267
268 if (!('edges' in data)) {
269 throw new Error('数据缺少 edges 字段')
270 }
271
272 if (!Array.isArray(data.nodes)) {
273 throw new Error('nodes 必须是数组')
274 }
275
276 for (let i = 0; i < data.nodes.length; i++) {
277 const node = data.nodes[i]
278
279 if (!node || typeof node !== 'object' || Array.isArray(node)) {
280 throw new Error(`nodes[${i}] 必须是对象`)
281 }
282
283 if (!('id' in node) || node.id === undefined || node.id === null || node.id === '') {
284 throw new Error(`nodes[${i}] 缺少 id`)
285 }
286 }
287
288 return data
289 }
290 document.addEventListener('paste', paste_node)
291
292 const delete_node = () => {

Callers 1

paste_nodeFunction · 0.85

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected