wowok_agent 2.1.39 → 2.2.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.
@@ -1 +1,401 @@
1
- import{GuardNodeSchema}from'../query/index.js';import{CallGuard_DataSchema}from'../call/guard.js';function detectFormat(a){const b=a['trim']();if(b['startsWith']('{')||b['startsWith']('['))return'json';return'markdown';}function extractJsonFromMarkdown(a){const b=/```(?:json)?\s*\n([\s\S]*?)```/g;let c,d=null;while((c=b['exec'](a))!==null){const e=c[0x1]['trim']();if(e['startsWith']('{')){const f=a['substring'](0x0,c['index']),g=(f['match'](/\n/g)||[])['length']+0x1;d={'json':e,'lineOffset':g};}}return d;}function parseMarkdownToGuardData(a){const b=[],c=extractJsonFromMarkdown(a);if(c)return{'data':c['json'],'errors':[]};const d={},f=a['match'](/(?:^|\n)#+\s*(?:Description|描述)[^\n]*\n+([^\n#]+)/i);f&&(d['description']=f[0x1]['trim']());const g=a['match'](/(?:^|\n)#+\s*(?:Table|数据表)[^\n]*\n+[\s\S]*?(?=(?:\n#+|$))/i);if(g){const j=g[0x0],k=j['match'](/\|[^\n]+\|/g);if(k&&k['length']>0x2){const l=k['slice'](0x2)['map'](m=>{const n=m['split']('|')['filter'](r=>r['trim']())['map'](r=>r['trim']()),o=n[0x2];let p;const q=o['match'](/\d+/);if(q)p=parseInt(q[0x0],0xa);else{const r=o['match'](/^([A-Za-z]+)/);if(r)p=r[0x1];else throw new Error('Invalid\x20value_type\x20in\x20table\x20row:\x20\x22'+o+'\x22.\x20Expected\x20a\x20number\x20(0-19)\x20or\x20type\x20name\x20(e.g.,\x20\x22U64\x22,\x20\x22Address\x22)');}return{'identifier':parseInt(n[0x0],0xa),'b_submission':n[0x1]['toLowerCase']()==='true','value_type':p,'value':n[0x3]==='-'?undefined:n[0x3],'name':n[0x4]==='-'?undefined:n[0x4]};});d['table']=l;}else d['table']=[];}else d['table']=[];const h=a['match'](/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(h){const m=h[0x1],n=m['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(n)try{d['root']=JSON['parse'](n[0x1]);}catch(o){b['push']({'message':'Failed\x20to\x20parse\x20root\x20JSON:\x20'+o['message'],'path':'/root'});}}const i=a['match'](/(?:^|\n)#+\s*(?:Rely|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(i){const p=i[0x1],q=p['match'](/\*\*Logic:\*\*\s*(AND|OR)/i),r=p['match'](/^\s*[-*]\s*(\S+)$/gm);if(q||r){const s=q?q[0x1]['toUpperCase']()==='AND':!![],t=r?r['map'](u=>u['replace'](/^\s*[-*]\s*/,'')['trim']()):[];d['rely']={'guards':t,'logic_or':!s};}else{const u=p['match'](/[-*]\s*guards?\s*:\s*\[([^\]]+)\]/i),v=p['match'](/[-*]\s*logic_or\s*:\s*(true|false)/i);(u||v)&&(d['rely']={'guards':u?u[0x1]['split'](',')['map'](w=>w['trim']()['replace'](/['"]/g,'')):[],'logic_or':v?v[0x1]['toLowerCase']()==='true':undefined});}}return{'data':d,'errors':b};}function parseJsonWithSourceMap(a,b=0x0){let c={},d;try{const f=a['split']('\x0a'),g=[0x0];for(let h=0x0;h<f['length'];h++){g['push'](g[h]+f[h]['length']+0x1);}return d=JSON['parse'](a),buildPointers(d,'',c,a,g,b),{'data':d,'map':{'pointers':c}};}catch(j){return null;}}function buildPointers(a,b,c,d,e,f){if(typeof a!=='object'||a===null)return;const g=findValuePosition(d,b,e);g!==undefined&&(c[b]={'value':{'line':g['line']+f,'column':g['column'],'pos':g['pos']}}),Array['isArray'](a)?a['forEach']((h,i)=>{buildPointers(h,b+'/'+i,c,d,e,f);}):Object['keys'](a)['forEach'](h=>{const i=h['replace'](/~/g,'~0')['replace'](/\//g,'~1');buildPointers(a[h],b+'/'+i,c,d,e,f);});}function findValuePosition(a,b,d){if(b===''){const l=a['match'](/\S/);if(l&&l['index']!==undefined)return getPosition(a,l['index'],d);return undefined;}const e=b['split']('/')['slice'](0x1);let f=0x0,g=0x0,h=![],k=![];for(let m=0x0;m<e['length'];m++){const n=e[m]['replace'](/~0/g,'~')['replace'](/~1/g,'/');let o=![];while(f<a['length']){const p=a[f];if(k){k=![],f++;continue;}if(p==='\x5c'){k=!![],f++;continue;}if(p==='\x22'){h=!h,f++;continue;}if(h){f++;continue;}if(p==='{'||p==='['){g++,f++;continue;}if(p==='}'||p===']'){g--,f++;continue;}if(m<e['length']-0x1||!isNaN(Number(n))){if(p==='\x22'&&g===m+0x1){const q=a['indexOf']('\x22',f+0x1);if(q!==-0x1){const r=a['slice'](f+0x1,q);if(r===n||!isNaN(Number(n))&&r===e[m-0x1]){f=q+0x1;while(f<a['length']&&(a[f]==='\x20'||a[f]===':'||a[f]==='\x0a'||a[f]==='\x0d'||a[f]==='\x09')){f++;}o=!![];break;}}}if(!isNaN(Number(n))&&p==='['){const s=f;let t=0x1,u=0x0,v=f+0x1;for(let w=f+0x1;w<a['length'];w++){const x=a[w];if(x==='[')t++;if(x===']'){t--;if(t===0x0)break;}if(x===','&&t===0x1){if(u===Number(n)){f=v;while(f<a['length']&&(a[f]==='\x20'||a[f]==='\x0a'||a[f]==='\x0d'||a[f]==='\x09')){f++;}o=!![];break;}u++,v=w+0x1;}}if(o)break;}}f++;}}while(f<a['length']&&(a[f]==='\x20'||a[f]==='\x0a'||a[f]==='\x0d'||a[f]==='\x09')){f++;}return getPosition(a,f,d);}function getPosition(a,b,c){let d=0x1;for(let f=0x0;f<c['length'];f++){if(c[f]>b)break;d=f+0x1;}const e=b-c[d-0x1]+0x1;return{'line':d,'column':e,'pos':b};}function formatZodPath(a){return'/'+a['map'](b=>String(b)['replace'](/~/g,'~0')['replace'](/\//g,'~1'))['join']('/');}export function parseGuardFromText(a){const b=[],c=a['trim'](),d=detectFormat(c);let f,g=null,h=0x0;if(d==='markdown'){const j=parseMarkdownToGuardData(c);if(j['errors']['length']>0x0)return{'success':![],'errors':j['errors']};if(typeof j['data']==='string'){const k=extractJsonFromMarkdown(c);if(k){h=k['lineOffset'];const l=parseJsonWithSourceMap(j['data'],h);if(l)f=l['data'],g=l['map'];else return b['push']({'message':'Failed\x20to\x20parse\x20JSON\x20from\x20markdown\x20code\x20block','path':'/'}),{'success':![],'errors':b};}else f=j['data'];}else f=j['data'];}else try{const m=parseJsonWithSourceMap(c,0x0);if(m)f=m['data'],g=m['map'];else return b['push']({'message':'Failed\x20to\x20parse\x20JSON\x20with\x20source\x20mapping','path':'/'}),{'success':![],'errors':b};}catch(n){const o=n,p=o['message']['match'](/position\s+(\d+)/);let q=0x1,r=0x1;if(p){const s=parseInt(p[0x1],0xa),t=c['substring'](0x0,s)['split']('\x0a');q=t['length'],r=t[t['length']-0x1]['length']+0x1;}return b['push']({'message':'JSON\x20parse\x20error:\x20'+o['message'],'path':'/','line':q,'column':r}),{'success':![],'errors':b};}const i=CallGuard_DataSchema['safeParse'](f);if(i['success'])return{'success':!![],'data':i['data'],'errors':[]};for(const u of i['error']['issues']){const v=formatZodPath(u['path']);let w,x;if(g?.['pointers'][v]){const z=g['pointers'][v];if(z['value'])w=z['value']['line'],x=z['value']['column'];else z['key']&&(w=z['key']['line'],x=z['key']['column']);}let y=u['message'];if(u['code']==='invalid_union'){const A=u;if(A['errors']){const B=A['errors']['map'](C=>C['issues']?.['map'](D=>D['message'])['join'](';\x20')||C['message'])['join']('\x20|\x20');y=y+'.\x20Alternatives:\x20'+B;}}b['push']({'message':y,'path':v,'line':w,'column':x});}return{'success':![],'errors':b};}export function formatGuardErrors(a){return a['map'](b=>{let c='Path:\x20'+b['path'];return b['line']!==undefined&&b['column']!==undefined&&(c+='\x20(line\x20'+b['line']+',\x20column\x20'+b['column']+')'),c+='\x0a\x20\x20Error:\x20'+b['message'],c;})['join']('\x0a\x0a');}export function validateGuardNode(a){const b=GuardNodeSchema['safeParse'](a);if(b['success'])return{'success':!![],'errors':[]};const c=b['error']['issues']['map'](d=>({'message':d['message'],'path':formatZodPath(d['path'])}));return{'success':![],'errors':c};}
1
+ import { GuardNodeSchema } from '../query/index.js';
2
+ import { CallGuard_DataSchema } from '../call/guard.js';
3
+ function detectFormat(text) {
4
+ const trimmed = text.trim();
5
+ if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
6
+ return 'json';
7
+ }
8
+ return 'markdown';
9
+ }
10
+ function extractJsonFromMarkdown(markdown) {
11
+ const codeBlockRegex = /```(?:json)?\s*\n([\s\S]*?)```/g;
12
+ let match;
13
+ let lastMatch = null;
14
+ while ((match = codeBlockRegex.exec(markdown)) !== null) {
15
+ const jsonContent = match[1].trim();
16
+ if (jsonContent.startsWith('{')) {
17
+ const beforeMatch = markdown.substring(0, match.index);
18
+ const lineOffset = (beforeMatch.match(/\n/g) || []).length + 1;
19
+ lastMatch = { json: jsonContent, lineOffset };
20
+ }
21
+ }
22
+ return lastMatch;
23
+ }
24
+ function parseMarkdownToGuardData(markdown) {
25
+ const errors = [];
26
+ const jsonMatch = extractJsonFromMarkdown(markdown);
27
+ if (jsonMatch) {
28
+ return { data: jsonMatch.json, errors: [] };
29
+ }
30
+ const result = {};
31
+ const descriptionMatch = markdown.match(/(?:^|\n)#+\s*(?:Description|描述)[^\n]*\n+([^\n#]+)/i);
32
+ if (descriptionMatch) {
33
+ result.description = descriptionMatch[1].trim();
34
+ }
35
+ const tableMatch = markdown.match(/(?:^|\n)#+\s*(?:Table|数据表)[^\n]*\n+[\s\S]*?(?=(?:\n#+|$))/i);
36
+ if (tableMatch) {
37
+ const tableSection = tableMatch[0];
38
+ const tableRows = tableSection.match(/\|[^\n]+\|/g);
39
+ if (tableRows && tableRows.length > 2) {
40
+ const rows = tableRows.slice(2).map(row => {
41
+ const cells = row.split('|').filter(c => c.trim()).map(c => c.trim());
42
+ const valueTypeCell = cells[2];
43
+ let value_type;
44
+ const numericMatch = valueTypeCell.match(/\d+/);
45
+ if (numericMatch) {
46
+ value_type = parseInt(numericMatch[0], 10);
47
+ }
48
+ else {
49
+ const typeNameMatch = valueTypeCell.match(/^([A-Za-z]+)/);
50
+ if (typeNameMatch) {
51
+ value_type = typeNameMatch[1];
52
+ }
53
+ else {
54
+ throw new Error(`Invalid value_type in table row: "${valueTypeCell}". Expected a number (0-19) or type name (e.g., "U64", "Address")`);
55
+ }
56
+ }
57
+ return {
58
+ identifier: parseInt(cells[0], 10),
59
+ b_submission: cells[1].toLowerCase() === 'true',
60
+ value_type,
61
+ value: cells[3] === '-' ? undefined : cells[3],
62
+ name: cells[4] === '-' ? undefined : cells[4]
63
+ };
64
+ });
65
+ result.table = rows;
66
+ }
67
+ else {
68
+ result.table = [];
69
+ }
70
+ }
71
+ else {
72
+ result.table = [];
73
+ }
74
+ const rootMatch = markdown.match(/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);
75
+ if (rootMatch) {
76
+ const rootSection = rootMatch[1];
77
+ const rootJsonMatch = rootSection.match(/```(?:json)?\s*\n([\s\S]*?)```/);
78
+ if (rootJsonMatch) {
79
+ try {
80
+ result.root = JSON.parse(rootJsonMatch[1]);
81
+ }
82
+ catch (e) {
83
+ errors.push({
84
+ message: `Failed to parse root JSON: ${e.message}`,
85
+ path: '/root',
86
+ });
87
+ }
88
+ }
89
+ }
90
+ const relyMatch = markdown.match(/(?:^|\n)#+\s*(?:Rely|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);
91
+ if (relyMatch) {
92
+ const relySection = relyMatch[1];
93
+ const logicMatch = relySection.match(/\*\*Logic:\*\*\s*(AND|OR)/i);
94
+ const guardListMatches = relySection.match(/^\s*[-*]\s*(\S+)$/gm);
95
+ if (logicMatch || guardListMatches) {
96
+ const logic_and = logicMatch ? logicMatch[1].toUpperCase() === 'AND' : true;
97
+ const guards = guardListMatches
98
+ ? guardListMatches.map(g => g.replace(/^\s*[-*]\s*/, '').trim())
99
+ : [];
100
+ result.rely = {
101
+ guards,
102
+ logic_or: !logic_and
103
+ };
104
+ }
105
+ else {
106
+ const guardsMatch = relySection.match(/[-*]\s*guards?\s*:\s*\[([^\]]+)\]/i);
107
+ const logicOrMatch = relySection.match(/[-*]\s*logic_or\s*:\s*(true|false)/i);
108
+ if (guardsMatch || logicOrMatch) {
109
+ result.rely = {
110
+ guards: guardsMatch
111
+ ? guardsMatch[1].split(',').map(g => g.trim().replace(/['"]/g, ''))
112
+ : [],
113
+ logic_or: logicOrMatch ? logicOrMatch[1].toLowerCase() === 'true' : undefined
114
+ };
115
+ }
116
+ }
117
+ }
118
+ return { data: result, errors };
119
+ }
120
+ function parseJsonWithSourceMap(text, lineOffset = 0) {
121
+ let pointers = {};
122
+ let data;
123
+ try {
124
+ const lines = text.split('\n');
125
+ const lineStarts = [0];
126
+ for (let i = 0; i < lines.length; i++) {
127
+ lineStarts.push(lineStarts[i] + lines[i].length + 1);
128
+ }
129
+ data = JSON.parse(text);
130
+ buildPointers(data, '', pointers, text, lineStarts, lineOffset);
131
+ return { data, map: { pointers } };
132
+ }
133
+ catch (e) {
134
+ return null;
135
+ }
136
+ }
137
+ function buildPointers(data, path, pointers, text, lineStarts, lineOffset) {
138
+ if (typeof data !== 'object' || data === null) {
139
+ return;
140
+ }
141
+ const pos = findValuePosition(text, path, lineStarts);
142
+ if (pos !== undefined) {
143
+ pointers[path] = {
144
+ value: { line: pos.line + lineOffset, column: pos.column, pos: pos.pos }
145
+ };
146
+ }
147
+ if (Array.isArray(data)) {
148
+ data.forEach((item, index) => {
149
+ buildPointers(item, `${path}/${index}`, pointers, text, lineStarts, lineOffset);
150
+ });
151
+ }
152
+ else {
153
+ Object.keys(data).forEach(key => {
154
+ const escapedKey = key.replace(/~/g, '~0').replace(/\//g, '~1');
155
+ buildPointers(data[key], `${path}/${escapedKey}`, pointers, text, lineStarts, lineOffset);
156
+ });
157
+ }
158
+ }
159
+ function findValuePosition(text, path, lineStarts) {
160
+ if (path === '') {
161
+ const match = text.match(/\S/);
162
+ if (match && match.index !== undefined) {
163
+ return getPosition(text, match.index, lineStarts);
164
+ }
165
+ return undefined;
166
+ }
167
+ const parts = path.split('/').slice(1);
168
+ let searchPos = 0;
169
+ let depth = 0;
170
+ let inString = false;
171
+ let escape = false;
172
+ for (let i = 0; i < parts.length; i++) {
173
+ const part = parts[i].replace(/~0/g, '~').replace(/~1/g, '/');
174
+ let found = false;
175
+ while (searchPos < text.length) {
176
+ const char = text[searchPos];
177
+ if (escape) {
178
+ escape = false;
179
+ searchPos++;
180
+ continue;
181
+ }
182
+ if (char === '\\') {
183
+ escape = true;
184
+ searchPos++;
185
+ continue;
186
+ }
187
+ if (char === '"') {
188
+ inString = !inString;
189
+ searchPos++;
190
+ continue;
191
+ }
192
+ if (inString) {
193
+ searchPos++;
194
+ continue;
195
+ }
196
+ if (char === '{' || char === '[') {
197
+ depth++;
198
+ searchPos++;
199
+ continue;
200
+ }
201
+ if (char === '}' || char === ']') {
202
+ depth--;
203
+ searchPos++;
204
+ continue;
205
+ }
206
+ if (i < parts.length - 1 || !isNaN(Number(part))) {
207
+ if (char === '"' && depth === i + 1) {
208
+ const endQuote = text.indexOf('"', searchPos + 1);
209
+ if (endQuote !== -1) {
210
+ const key = text.slice(searchPos + 1, endQuote);
211
+ if (key === part || (!isNaN(Number(part)) && key === parts[i - 1])) {
212
+ searchPos = endQuote + 1;
213
+ while (searchPos < text.length && (text[searchPos] === ' ' || text[searchPos] === ':' || text[searchPos] === '\n' || text[searchPos] === '\r' || text[searchPos] === '\t')) {
214
+ searchPos++;
215
+ }
216
+ found = true;
217
+ break;
218
+ }
219
+ }
220
+ }
221
+ if (!isNaN(Number(part)) && char === '[') {
222
+ const arrayStart = searchPos;
223
+ let arrayDepth = 1;
224
+ let itemIndex = 0;
225
+ let itemStart = searchPos + 1;
226
+ for (let j = searchPos + 1; j < text.length; j++) {
227
+ const c = text[j];
228
+ if (c === '[')
229
+ arrayDepth++;
230
+ if (c === ']') {
231
+ arrayDepth--;
232
+ if (arrayDepth === 0)
233
+ break;
234
+ }
235
+ if (c === ',' && arrayDepth === 1) {
236
+ if (itemIndex === Number(part)) {
237
+ searchPos = itemStart;
238
+ while (searchPos < text.length && (text[searchPos] === ' ' || text[searchPos] === '\n' || text[searchPos] === '\r' || text[searchPos] === '\t')) {
239
+ searchPos++;
240
+ }
241
+ found = true;
242
+ break;
243
+ }
244
+ itemIndex++;
245
+ itemStart = j + 1;
246
+ }
247
+ }
248
+ if (found)
249
+ break;
250
+ }
251
+ }
252
+ searchPos++;
253
+ }
254
+ }
255
+ while (searchPos < text.length && (text[searchPos] === ' ' || text[searchPos] === '\n' || text[searchPos] === '\r' || text[searchPos] === '\t')) {
256
+ searchPos++;
257
+ }
258
+ return getPosition(text, searchPos, lineStarts);
259
+ }
260
+ function getPosition(text, pos, lineStarts) {
261
+ let line = 1;
262
+ for (let i = 0; i < lineStarts.length; i++) {
263
+ if (lineStarts[i] > pos)
264
+ break;
265
+ line = i + 1;
266
+ }
267
+ const column = pos - lineStarts[line - 1] + 1;
268
+ return { line, column, pos };
269
+ }
270
+ function formatZodPath(path) {
271
+ return '/' + path.map(p => String(p).replace(/~/g, '~0').replace(/\//g, '~1')).join('/');
272
+ }
273
+ export function parseGuardFromText(text) {
274
+ const errors = [];
275
+ const trimmed = text.trim();
276
+ const format = detectFormat(trimmed);
277
+ let parsedData;
278
+ let sourceMap = null;
279
+ let lineOffset = 0;
280
+ if (format === 'markdown') {
281
+ const mdResult = parseMarkdownToGuardData(trimmed);
282
+ if (mdResult.errors.length > 0) {
283
+ return { success: false, errors: mdResult.errors };
284
+ }
285
+ if (typeof mdResult.data === 'string') {
286
+ const jsonMatch = extractJsonFromMarkdown(trimmed);
287
+ if (jsonMatch) {
288
+ lineOffset = jsonMatch.lineOffset;
289
+ const parsed = parseJsonWithSourceMap(mdResult.data, lineOffset);
290
+ if (parsed) {
291
+ parsedData = parsed.data;
292
+ sourceMap = parsed.map;
293
+ }
294
+ else {
295
+ errors.push({
296
+ message: 'Failed to parse JSON from markdown code block',
297
+ path: '/',
298
+ });
299
+ return { success: false, errors };
300
+ }
301
+ }
302
+ else {
303
+ parsedData = mdResult.data;
304
+ }
305
+ }
306
+ else {
307
+ parsedData = mdResult.data;
308
+ }
309
+ }
310
+ else {
311
+ try {
312
+ const parsed = parseJsonWithSourceMap(trimmed, 0);
313
+ if (parsed) {
314
+ parsedData = parsed.data;
315
+ sourceMap = parsed.map;
316
+ }
317
+ else {
318
+ errors.push({
319
+ message: 'Failed to parse JSON with source mapping',
320
+ path: '/',
321
+ });
322
+ return { success: false, errors };
323
+ }
324
+ }
325
+ catch (e) {
326
+ const jsonError = e;
327
+ const lineMatch = jsonError.message.match(/position\s+(\d+)/);
328
+ let line = 1;
329
+ let column = 1;
330
+ if (lineMatch) {
331
+ const pos = parseInt(lineMatch[1], 10);
332
+ const lines = trimmed.substring(0, pos).split('\n');
333
+ line = lines.length;
334
+ column = lines[lines.length - 1].length + 1;
335
+ }
336
+ errors.push({
337
+ message: `JSON parse error: ${jsonError.message}`,
338
+ path: '/',
339
+ line,
340
+ column,
341
+ });
342
+ return { success: false, errors };
343
+ }
344
+ }
345
+ const result = CallGuard_DataSchema.safeParse(parsedData);
346
+ if (result.success) {
347
+ return { success: true, data: result.data, errors: [] };
348
+ }
349
+ for (const issue of result.error.issues) {
350
+ const path = formatZodPath(issue.path);
351
+ let line;
352
+ let column;
353
+ if (sourceMap?.pointers[path]) {
354
+ const pointer = sourceMap.pointers[path];
355
+ if (pointer.value) {
356
+ line = pointer.value.line;
357
+ column = pointer.value.column;
358
+ }
359
+ else if (pointer.key) {
360
+ line = pointer.key.line;
361
+ column = pointer.key.column;
362
+ }
363
+ }
364
+ let message = issue.message;
365
+ if (issue.code === 'invalid_union') {
366
+ const unionIssue = issue;
367
+ if (unionIssue.errors) {
368
+ const unionErrors = unionIssue.errors.map((e) => e.issues?.map((i) => i.message).join('; ') || e.message).join(' | ');
369
+ message = `${message}. Alternatives: ${unionErrors}`;
370
+ }
371
+ }
372
+ errors.push({
373
+ message,
374
+ path,
375
+ line,
376
+ column,
377
+ });
378
+ }
379
+ return { success: false, errors };
380
+ }
381
+ export function formatGuardErrors(errors) {
382
+ return errors.map(e => {
383
+ let msg = `Path: ${e.path}`;
384
+ if (e.line !== undefined && e.column !== undefined) {
385
+ msg += ` (line ${e.line}, column ${e.column})`;
386
+ }
387
+ msg += `\n Error: ${e.message}`;
388
+ return msg;
389
+ }).join('\n\n');
390
+ }
391
+ export function validateGuardNode(node) {
392
+ const result = GuardNodeSchema.safeParse(node);
393
+ if (result.success) {
394
+ return { success: true, errors: [] };
395
+ }
396
+ const errors = result.error.issues.map(issue => ({
397
+ message: issue.message,
398
+ path: formatZodPath(issue.path),
399
+ }));
400
+ return { success: false, errors };
401
+ }
@@ -1 +1,22 @@
1
- import{GUARDQUERY}from'wowok';const validGuardQueryIds=new Set(GUARDQUERY['map'](a=>a['id'])),validGuardQueryNames=new Set(GUARDQUERY['map'](a=>a['name']['toLowerCase']()));export const isValidGuardQueryId=a=>{return validGuardQueryIds['has'](a);};export const isValidGuardQueryName=a=>{return validGuardQueryNames['has'](a['toLowerCase']());};export const isValidGuardQueryIdOrName=a=>{if(typeof a==='number')return isValidGuardQueryId(a);return isValidGuardQueryName(a);};export const getGuardQueryByIdOrName=a=>{if(typeof a==='number')return GUARDQUERY['find'](b=>b['id']===a);return GUARDQUERY['find'](b=>b['name']['toLowerCase']()===a['toLowerCase']());};export const GUARD_QUERY_NAMES=GUARDQUERY['map'](a=>a['name']);
1
+ import { GUARDQUERY } from "wowok";
2
+ const validGuardQueryIds = new Set(GUARDQUERY.map(item => item.id));
3
+ const validGuardQueryNames = new Set(GUARDQUERY.map(item => item.name.toLowerCase()));
4
+ export const isValidGuardQueryId = (id) => {
5
+ return validGuardQueryIds.has(id);
6
+ };
7
+ export const isValidGuardQueryName = (name) => {
8
+ return validGuardQueryNames.has(name.toLowerCase());
9
+ };
10
+ export const isValidGuardQueryIdOrName = (input) => {
11
+ if (typeof input === 'number') {
12
+ return isValidGuardQueryId(input);
13
+ }
14
+ return isValidGuardQueryName(input);
15
+ };
16
+ export const getGuardQueryByIdOrName = (input) => {
17
+ if (typeof input === 'number') {
18
+ return GUARDQUERY.find(item => item.id === input);
19
+ }
20
+ return GUARDQUERY.find(item => item.name.toLowerCase() === input.toLowerCase());
21
+ };
22
+ export const GUARD_QUERY_NAMES = GUARDQUERY.map(item => item.name);