MCPcopy Create free account
hub / github.com/WebFreak001/code-debug / MINode

Class MINode

src/backend/mi_parse.ts:57–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57export class MINode implements MIInfo {
58 token: number;
59 outOfBandRecord: { isStream: boolean, type: string, asyncClass: string, output: [string, any][], content: string }[];
60 resultRecords: { resultClass: string, results: [string, any][] };
61
62 constructor(token: number, info: { isStream: boolean, type: string, asyncClass: string, output: [string, any][], content: string }[], result: { resultClass: string, results: [string, any][] }) {
63 this.token = token;
64 this.outOfBandRecord = info;
65 this.resultRecords = result;
66 }
67
68 record(path: string): any {
69 if (!this.outOfBandRecord)
70 return undefined;
71 return MINode.valueOf(this.outOfBandRecord[0].output, path);
72 }
73
74 result(path: string): any {
75 if (!this.resultRecords)
76 return undefined;
77 return MINode.valueOf(this.resultRecords.results, path);
78 }
79
80 static valueOf(start: any, path: string): any {
81 if (!start)
82 return undefined;
83 const pathRegex = /^\.?([a-zA-Z_\-][a-zA-Z0-9_\-]*)/;
84 const indexRegex = /^\[(\d+)\](?:$|\.)/;
85 path = path.trim();
86 if (!path)
87 return start;
88 let current = start;
89 do {
90 let target = pathRegex.exec(path);
91 if (target) {
92 path = path.substring(target[0].length);
93 if (current.length && typeof current != "string") {
94 const found = [];
95 for (const element of current) {
96 if (element[0] == target[1]) {
97 found.push(element[1]);
98 }
99 }
100 if (found.length > 1) {
101 current = found;
102 } else if (found.length == 1) {
103 current = found[0];
104 } else return undefined;
105 } else return undefined;
106 } else if (path[0] == '@') {
107 current = [current];
108 path = path.substring(1);
109 } else {
110 target = indexRegex.exec(path);
111 if (target) {
112 path = path.substring(target[0].length);
113 const i = parseInt(target[1]);
114 if (current.length && typeof current != "string" && i >= 0 && i < current.length) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected