MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / buildPayload

Function buildPayload

src/math-json/scripts/generate_OPERATORS.ts:113–211  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

111function topLevelParams(args: string): string[] {
112 const out: string[] = [];
113 let depth = 0;
114 let current = '';
115 for (let i = 0; i < args.length; i++) {
116 const c = args[i];
117 if (c === '(' || c === '<' || c === '[') depth++;
118 else if ((c === '>' && args[i - 1] !== '-') || c === ')' || c === ']')
119 depth--;
120 if (c === ',' && depth === 0) {
121 out.push(current.trim());
122 current = '';
123 } else current += c;
124 }
125 out.push(current.trim());
126 return out.filter(Boolean);
127}
128
129function asDescription(def: DefRecord): string | undefined {
130 const description = def.description;
131 if (Array.isArray(description)) {
132 const text = description.join('\n\n').trim();
133 return text === '' ? undefined : text;
134 }
135 if (typeof description === 'string') {
136 const text = description.trim();
137 return text === '' ? undefined : text;
138 }
139 return undefined;
140}
141
142function asExamples(def: DefRecord): string[] | undefined {
143 const examples = def.examples;
144 if (!examples) return undefined;
145 if (Array.isArray(examples)) return examples.map((x: unknown) => String(x));
146 return [String(examples)];
147}
148
149function buildPayload() {
150 const definitions: { library: string; name: string; def: DefRecord }[] = [];
151
152 for (const lib of getStandardLibrary()) {
153 const tables = lib.definitions
154 ? Array.isArray(lib.definitions)
155 ? lib.definitions
156 : [lib.definitions]
157 : [];
158
159 for (const table of tables) {
160 for (const [name, def] of Object.entries(table)) {
161 if (isObj(def)) definitions.push({ library: lib.name, name, def });
162 }
163 }
164 }
165
166 const operators = definitions
167 .filter((x) => x.name !== '__unit__' && isOperatorDef(x.def))
168 .map(({ library, name, def }) => {
169 const entry: {
170 name: string;

Callers 1

Calls 9

getStandardLibraryFunction · 0.85
isObjFunction · 0.85
arityFromSignatureFunction · 0.85
asDescriptionFunction · 0.85
asExamplesFunction · 0.85
isOperatorDefFunction · 0.70
isValueDefFunction · 0.70
entriesMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected