MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / querySource

Function querySource

__tests__/explore-named-file-valve.test.ts:158–186  ·  view source on GitHub ↗

A QuerySet whose named methods are interleaved with unrelated cache slots.

()

Source from the content-addressed store, hash-verified

156
157 /** A QuerySet whose named methods are interleaved with unrelated cache slots. */
158 function querySource(): string {
159 const L = [
160 'export class QuerySet {',
161 ' steps: Array<{ op: string; at: number; arg: unknown }> = [];',
162 '',
163 ' chain(op: string): QuerySet {',
164 ' const next = new QuerySet();',
165 ' next.steps = [...this.steps];',
166 ' return next;',
167 ' }',
168 ];
169 let slot = 0;
170 const cacheSlot = () => {
171 const i = slot++;
172 L.push('', ` cacheSlot${i}(key: string): string {`);
173 for (let k = 0; k < 8; k++) L.push(` key = key.padStart(${k + (i % 7)}, '${String.fromCharCode(97 + ((i + k) % 26))}');`);
174 L.push(' return key;', ' }');
175 };
176 for (const name of METHODS) {
177 L.push('', ` ${name}(...args: unknown[]): QuerySet {`, ` const clone = this.chain('${name}');`);
178 for (let i = 0; i < 40; i++) L.push(` clone.steps.push({ op: '${name}', at: ${i}, arg: args[${i % 3}] ?? null });`);
179 L.push(' return clone;', ' }');
180 cacheSlot();
181 cacheSlot();
182 }
183 while (slot < 70) cacheSlot();
184 L.push('}');
185 return L.join('\n') + '\n';
186 }
187
188 function listFilterSource(): string {
189 return [

Calls 3

cacheSlotFunction · 0.85
pushMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected