repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
amica
github_2023
semperai
typescript
calculateNewDimensions
function calculateNewDimensions(width: number, height: number, maxDimension: number): Dimensions { if (width <= maxDimension && height <= maxDimension) { return { width, height }; } const aspectRatio = width / height; if (width > height) { return { width: maxDimension, height: Math.round(...
// Calculate new dimensions maintaining aspect ratio
https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/utils/textureDownscaler.ts#L76-L92
c5829dd25a4ad93cc26bc01b4c8520fd3ef51916
amica
github_2023
semperai
typescript
downscaleModelTextures
async function downscaleModelTextures(gltf: any, maxDimension: number = 1024): Promise<any> { const texturePromises: Promise<void>[] = []; const processedTextures = new Set<THREE.Texture>(); gltf.scene.traverse((node: THREE.Object3D) => { if (!(node as THREE.Mesh).isMesh) return; if (node instanceof TH...
// Main function to downscale textures in a GLTF model
https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/utils/textureDownscaler.ts#L134-L176
c5829dd25a4ad93cc26bc01b4c8520fd3ef51916
time-picker
github_2023
openstatusHQ
typescript
handleSelect
const handleSelect = (newDay: Date | undefined) => { if (!newDay) return; if (!date) { setDate(newDay); return; } const diff = newDay.getTime() - date.getTime(); const diffInDays = diff / (1000 * 60 * 60 * 24); const newDateFull = add(date, { days: Math.ceil(diffInDays) }); setDa...
/** * carry over the current time when a user clicks a new day * instead of resetting to 00:00 */
https://github.com/openstatusHQ/time-picker/blob/80e83c42fedd8024592281edf4bfd3a2c58e51c4/src/components/time-picker/date-time-picker.tsx#L24-L34
80e83c42fedd8024592281edf4bfd3a2c58e51c4
testpilot
github_2023
githubnext
typescript
getFailedStats
function getFailedStats(data: ITestReport) { const failures = data.tests .filter((test) => test.status === "FAILED") .map((test) => test.err as ITestFailureInfo); const numFailing = failures.length; let numAssertionErrors = 0; let numFileSysErrors = 0; //correctness errors include Type errors, Refer...
/** * Categorize types of failures in given tests * @param data report data, as found in report.json * @returns an object with the number of occurrences of each type of failure */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/parse_reports.ts#L89-L126
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
isCorrectnessError
function isCorrectnessError(err: ITestFailureInfo) { if (!err.stack) return false; return ( err.stack.includes("ReferenceError") || err.stack.includes("TypeError") || err.stack.includes("done() invoked with non-Error") || err.stack.includes("Maximum call stack size exceeded") ); }
/** * Checks if tests fails because of a correctness error (right now: type error, reference error, done error, infinite recursion/call stack error) * @param err test failure info to check * @returns true/false */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/parse_reports.ts#L138-L146
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
isAssertionError
function isAssertionError(err: ITestFailureInfo) { if (!err.stack) return false; return err.stack.includes("AssertionError"); }
/** * Checks if tests fails because of an assertion error * @param err test failure info to check * @returns true/false */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/parse_reports.ts#L153-L156
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
isFileSysError
function isFileSysError(err: ITestFailureInfo) { if (!err.code) return false; return FILE_SYS_ERRORS.includes(err.code); }
/** * Checks if tests fails because of file system errors, as defined in FILE_SYS_ERRORS * @param err test failure info to check * @returns true/false */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/parse_reports.ts#L163-L166
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
isTimedOutTest
function isTimedOutTest(err: ITestFailureInfo) { if (!err.code) return false; return err.code === "ERR_MOCHA_TIMEOUT"; }
/** * Checks if tests fails because of time outs * @param err test failure info to check * @returns true/false */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/parse_reports.ts#L173-L176
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
getAPIStats
function getAPIStats(snippetsReport: string, apiReport: string) { let numFunctions = -1; let numFunctionsWithExamples = -1; let numFunctionsWithDocComments = -1; if (fs.existsSync(apiReport)) { const apiData = JSON.parse(fs.readFileSync(apiReport, "utf8")) as [ { descriptor: FunctionDescriptor } ...
/*** * Parse `api.json` and `snippetMap.json` files of a project and return an object containing the following statistics: * - `numFunctions`: number of functions in the project * - `numFunctionsWithExamples`: number of functions with at least one example * - `numFunctionsWithDocComments`: number of functions with ...
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/parse_reports.ts#L342-L376
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
getNumUniquelyCoveringTests
function getNumUniquelyCoveringTests(tests: ReportForTest[]) { const stmtCovMap = new Map(); // map from statement to list of tests covering that statement for (const test of tests) { for (const coveredStmt of test.coveredStatements ?? []) { if (!stmtCovMap.has(coveredStmt)) { stmtCovMap.set(cove...
/** * Finds number of tests that cover at least one statement no other test covers * @param tests object containing all tests * @returns number of tests that cover at least one statement no other test covers */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/parse_reports.ts#L383-L405
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
PerformanceMeasurer.getApiExplorationTime
getApiExplorationTime(): number | undefined { if (this.apiExplorationTime && this.docCommentExtractionTime) { return Math.max( 0, this.apiExplorationTime - this.docCommentExtractionTime ); } return this.apiExplorationTime; }
/** * Get the time (in milliseconds) taken to explore package API, not * including time to extract doc comments. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/performanceMeasurer.ts#L65-L73
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
PerformanceMeasurer.getDocCommentExtractionTime
getDocCommentExtractionTime(): number | undefined { return this.docCommentExtractionTime; }
/** Get the time (in milliseconds) taken to extract doc comments. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/performanceMeasurer.ts#L76-L78
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
PerformanceMeasurer.getSnippetExtractionTime
getSnippetExtractionTime(): number | undefined { return this.snippetExtractionTime; }
/** Get the time (in milliseconds) taken to extract snippets. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/performanceMeasurer.ts#L81-L83
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
PerformanceMeasurer.getTestDuration
getTestDuration(testName: string): number | undefined { return this.testDurations.get(testName); }
/** Get the time (in milliseconds) taken to run the given test. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/performanceMeasurer.ts#L86-L88
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
PerformanceMeasurer.getCodexQueryTimes
getCodexQueryTimes(): [CodexPostOptions, number][] { return this.codexQueryTimes; }
/** * Get a list of response times (in milliseconds) for Codex queries * together with the corresponding request parameters. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/performanceMeasurer.ts#L94-L96
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
PerformanceMeasurer.getTotalCodexQueryTime
getTotalCodexQueryTime(): number { return this.codexQueryTimes.reduce( (sum, [, duration]) => sum + duration, 0 ); }
/** Get the cumulative response time (in milliseconds) for all Codex queries. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/performanceMeasurer.ts#L99-L104
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
PerformanceMeasurer.getTotalTime
getTotalTime(): number { return performance.now() - this.start; }
/** Get the total elapsed time (in milliseconds) since this measurer was instantiated. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/performanceMeasurer.ts#L107-L109
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
TestResultCollector.constructor
constructor( packageName: string, private readonly packagePath: string, private readonly outputDir: string, private readonly api: APIFunction[], private readonly snippetMap: Map<string, string[]>, private readonly perf: PerformanceMeasurer, snippetsTypeAsString: string, numSnippets: numb...
/** * constructor registers meta-data associated with a test run * * @param outputDir: the directory in which to write the report and other files * @param snippetsTypeAsString: the type of snippets used to generate the tests (code, doc, both, or none) * @param numSnippets: number of snippets to include i...
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/testResultCollector.ts#L37-L61
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
TestResultCollector.getCoveredStatements
private getCoveredStatements(outcome: TestOutcome) { if ( outcome.status !== TestStatus.PASSED || outcome.coverageReport === undefined ) { return []; } const coveredStatements = []; const coverage = JSON.parse( fs.readFileSync(outcome.coverageReport, "utf8") ); for (c...
/** * Get the list of statements covered by the test with the given outcome. * * Tests that do not pass or that do not have a coverage summary are not * considered to cover any statements. For passing tests, covered statements are * represented in the form * '<file>@<startLine>:<startColumn>-<endLine>...
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/testResultCollector.ts#L133-L151
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
TestResultCollector.computeNrUniqueSnippets
private computeNrUniqueSnippets(): number { const uniqueSnippets = new Set<string>(); for (const snippetGroup of this.snippetMap.values()) { for (const snippet of snippetGroup) { uniqueSnippets.add(snippet); } } return uniqueSnippets.size; }
/** * compute the number of unique snippets that are available in the snippet map * @returns the number of unique snippets */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/testResultCollector.ts#L157-L165
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
TestResultCollector.getTestLabel
private getTestLabel(test: ITestInfo): string { const testName = test.testName; if (test.outcome.status === TestStatus.PASSED) { return "\u001b[32m" + "\u2713" + testName + "\u001b[0m"; } else if (test.outcome.status === TestStatus.FAILED) { return "\u001b[31m" + "\u2717" + testName + "\u001b[0m...
/** * For passing tests, preprend a checkmark and make the text green. * For failing tests, prepend an 'x' and make the text red. * For other tests, prepend a '?' and make the text purple. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/testResultCollector.ts#L172-L181
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
TestResultCollector.reportAPICoverage
private reportAPICoverage() { console.log("API coverage:"); const testsPerAPI = new Map<string, Set<ITestInfo>>(); for (const test of this.tests.values()) { const api = test.api; if (!testsPerAPI.has(api)) { testsPerAPI.set(api, new Set<ITestInfo>()); } testsPerAPI.get(api)!....
/** * print summary of test results for each API method */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/testResultCollector.ts#L186-L200
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
TestResultCollector.createOutputDir
private createOutputDir() { if (fs.existsSync(this.outputDir)) { fs.rmdirSync(this.outputDir, { recursive: true }); } fs.mkdirSync(this.outputDir, { recursive: true }); fs.mkdirSync(path.join(this.outputDir, "tests")); fs.mkdirSync(path.join(this.outputDir, "prompts")); fs.mkdirSync(path.j...
/** * Create directory for output files if it does not exist. If it does exist, delete it and its contents and create a new one. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/benchmark/testResultCollector.ts#L293-L301
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
Codex.query
public async query( prompt: string, requestPostOptions: PostOptions = {} ): Promise<Set<string>> { const headers = { "Content-Type": "application/json", ...JSON.parse(this.authHeaders), }; const options = { ...defaultPostOptions, // options provided to constructor override ...
/** * Query Codex for completions with a given prompt. * * @param prompt The prompt to use for the completion. * @param requestPostOptions The options to use for the request. * @returns A promise that resolves to a set of completions. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/codex.ts#L52-L123
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
Codex.completions
public async completions( prompt: string, temperature: number ): Promise<Set<string>> { try { let result = new Set<string>(); for (const completion of await this.query(prompt, { temperature })) { result.add(trimCompletion(completion)); } return result; } catch (err: any...
/** * Get completions from Codex and postprocess them as needed; print a warning if it did not produce any * * @param prompt the prompt to use */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/codex.ts#L130-L144
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
getSnippetsFromCodeFiles
function getSnippetsFromCodeFiles(files: Set<string>): Set<string> { let snippets = new Set<string>(); files.forEach((file) => snippets.add(fs.readFileSync(file, "utf8"))); return snippets; }
/** * Get code file contents for use as snippets * @param files set of code files to extract snippets from * @returns a set of snippets in the given code files */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/docSnippets.ts#L37-L42
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
nrLinesInSnippet
function nrLinesInSnippet(snippet: string): number { return snippet.split("\n").length; }
/** * Find the number of lines in a given snippet * @param snippet the snippet * @returns the number of lines in the given snippet */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/docSnippets.ts#L163-L165
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
isExampleDir
function isExampleDir(dirPath: string): boolean { const exampleDirs = ["examples", "example", "demo"]; return exampleDirs.includes(path.basename(dirPath)); }
/** * Check if given directory path ends with one the predefined example directories * @param dirPath directory path to check * @returns true if dirPath ends with one of the predefined example directories, false otherwise */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/docSnippets.ts#L204-L208
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
isJSFile
function isJSFile(fileName: string): boolean { return jsExtensions.code.includes(path.extname(fileName).slice(1)); }
/*** * Check if given file has a JS code file extension * @param fileName file name to check * @returns true if fileName has JS code file extension, false otherwise */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/docSnippets.ts#L215-L217
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
findExampleFiles
function findExampleFiles(directoryName: string): [Set<string>, Set<string>] { let markDownFiles = new Set<string>(); let exampleCodeFiles = new Set<string>(); try { let files = fs.readdirSync(directoryName); for (let file of files) { let filePath = directoryName + "/" + file; if ( isE...
/** * Recursively search for markdown files and example code files in the given directory * @param dir the directory to search * @returns a set of markdown files and a set of example code files, in the given directory **/
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/docSnippets.ts#L224-L252
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
tokenize
function tokenize(code: string): string[] { const word = /[a-zA-Z_$][\w$]*/g; return code.match(word) || []; }
/** * Tokenize a code block into a list of alphanumeric words, ignoring all other characters. * @param code the code block to tokenize * @returns a list of tokens in the given code block */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/docSnippets.ts#L286-L289
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
stripFencing
function stripFencing(snippet: string): string { let lines = snippet.split("\n"); lines.shift(); lines.pop(); return lines.join("\n"); }
/** * Remove the first and last line from a fenced code block * @param codeBlock the code block to remove the first and last line from * @returns the code block with the first and last line removed */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/docSnippets.ts#L296-L301
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
removeTrailingComments
function removeTrailingComments(snippet: string) { let lines = snippet.split("\n"); while (true) { let line = lines.pop() as string; if (line.startsWith("//") || line?.length === 0) { break; } } return lines.join("\n"); }
/** * Remove trailing comments at the end of a snippet (these may arise if * code blocks are split when they contain multiple examples. * @param snippet the snippet to remove trailing comments from * @returns the snippet with trailing comments removed */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/docSnippets.ts#L309-L318
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
extractSnippetsFromCodeBlock
function extractSnippetsFromCodeBlock(codeBlock: string): Set<string> { let snippets = new Set<string>(); let lines = codeBlock.split("\n"); let startOfCurrentSnippet = 0; let declaredVars = new Set<string>(); for (let i = 0; i < lines.length; i++) { let line = lines[i]; if ( line.startsWith("le...
/** * Sometimes, a fenced code block contains multiple examples. In such cases, we assume that * a new snippet is started whenever a previously declared variable is redeclared. * @param codeBlock the code block to extract snippets from * @returns a set of snippets in the given code block */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/docSnippets.ts#L326-L357
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
APIFunction.fromSignature
public static fromSignature( signature: string, implementation: string = "" ): APIFunction { const match = signature.match( /^(class )?([-\w$]+(?:\.[\w$]+)*)(\(.*\))( async)?$/ ); if (!match) throw new Error(`Invalid signature: ${signature}`); const [, isConstructor, accessPath, paramete...
/** * Parse a given signature into an API function. * * The signature is expected to consist of an optional initial `class `, then * a dot-separated access path (starting with the package name, ending with * the function name), followed by a parenthesised list of parameters, * optionally followed by `...
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/exploreAPI.ts#L98-L115
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
APIFunction.toJSON
public toJSON(): object { return { accessPath: this.accessPath, descriptor: this.descriptor, packageName: this.packageName, }; }
/** Serialize the API function to a JSON object. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/exploreAPI.ts#L118-L124
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
APIFunction.fromJSON
public static fromJSON(json: object): APIFunction { const { accessPath, descriptor, packageName } = json as any; return new APIFunction(accessPath, descriptor, packageName); }
/** Deserialize an API function from a JSON object. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/exploreAPI.ts#L127-L130
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
APIFunction.functionName
public get functionName(): string { return this.accessPath.split(".").pop()!; }
/** The name of the function itself. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/exploreAPI.ts#L133-L135
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
APIFunction.signature
public get signature(): string { const { signature, isAsync, isConstructor } = this.descriptor; return ( (isConstructor ? "class " : "") + this.accessPath + signature + (isAsync ? " async" : "") ); }
/** The full signature of the function. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/exploreAPI.ts#L138-L146
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
isConstructor
function isConstructor(fn: Function) { return funcToString.call(fn).startsWith("class "); }
/** * Determine if a function is a constructor */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/exploreAPI.ts#L154-L156
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
exploreExports
function exploreExports( pkgName: string, pkgExports: any, docComments: Map<string, string> ): API { const api = new API(); const seen = new Set<any>(); function explore(accessPath: string, value: any) { if (seen.has(value)) { return; } else { seen.add(value); } const descripto...
/** * Determines the set of (`path`, `type`) pairs that constitute an API. * * @param pkgName the name of the package to explore * @param pkgExports the object returned by `require(pkgName)` */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/exploreAPI.ts#L264-L312
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
TestGenerator.generateAndValidateTests
async generateAndValidateTests(fun: APIFunction) { for (const temperature of this.temperatures) { let generatedPassingTests = false; const generatedPrompts = new Map<string, Prompt>(); const snippets = this.snippetMap(fun.functionName) ?? []; const worklist = [new Prompt(fun, snippets, defau...
/** * Generate tests for a given function and validate them. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/generateTests.ts#L40-L79
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
TestGenerator.validateCompletion
public validateCompletion( prompt: Prompt, completion: string, temperature: number ) { const testSource = prompt.completeTest(completion); const testInfo = this.collector.recordTestInfo( testSource ?? completion, prompt, prompt.fun.accessPath ); if (testInfo.prompts.leng...
/** * Build a test for the given prompt and completion, validate it, and return * a test info object. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/generateTests.ts#L85-L115
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
TestGenerator.refinePrompts
private refinePrompts( prompt: Prompt, completion: string, testInfo: ITestInfo, worklist: Prompt[] ) { for (const refiner of this.refiners) { for (const refinedPrompt of refiner.refine( prompt, completion, testInfo.outcome )) { const provenance = { ...
/** * Refine the prompt based on the test outcome, and add the refined prompts * to the worklist. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/generateTests.ts#L121-L141
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
MochaValidator.copyCoverageData
public static copyCoverageData(src: string, dest: string) { for (const file of fs.readdirSync(src)) { if (file.endsWith(".json") && file !== "coverage-final.json") { fs.copyFileSync(path.join(src, file), path.join(dest, file)); } } }
/** * Copy all .json files from `src` to `dest` (which must exist). */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/mochaValidator.ts#L227-L233
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
Prompt.assembleUsageSnippets
private assembleUsageSnippets(): string { if (!this.options.includeSnippets) { return ""; } else { return this.usageSnippets .map((snippet, index) => { const lines = snippet.split("\n"); const commentedLines = lines.map((line) => `// ${line}\n`); return `// usag...
/** * Assemble the usage snippets into a single string. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/promptCrafting.ts#L116-L128
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
Prompt.assemble
public assemble(): string { return ( this.imports + this.assembleUsageSnippets() + this.docComment + this.signature + this.functionBody + this.suiteHeader + this.testHeader ); }
/** * Assemble a prompt to send to the model from the structured * representation. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/promptCrafting.ts#L134-L144
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
Prompt.completeTest
public completeTest( body: string, stubOutHeaders: boolean = true ): string | undefined { let fixed = closeBrackets( this.imports + (stubOutHeaders ? // stub out suite header and test header so we don't double-count identical tests "describe('test suite', function() {\n...
/** * Given a test body suggested by the model, assemble a complete, * syntactically correct test. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/promptCrafting.ts#L150-L167
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
Snippets.createPartitions
createPartitions(snippets: Set<string>): Partition[] { return [...snippets].map((snippet) => new Set([snippet])); }
/** * Create the partitions. Initially each snippet is in its own partition. * @param snippets The snippets to partition. * @returns The partitions. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/snippetHelper.ts#L24-L26
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
Snippets.computeDistance
computeDistance(a: string, b: string): number { // construct key for cache; this isn't injective, but it's good enough for our purposes const key = `${a}|||${b}`; if (this.distanceCache.has(key)) { return this.distanceCache.get(key)!; } else { const distance = new levenshtein(a, b).distance;...
/** * Compute the Levenshtein distance between two strings, utilizing a cache. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/snippetHelper.ts#L31-L41
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
Snippets.comparePartitions
comparePartitions(partition1: Partition, partition2: Partition): number { let lowestDistance = Number.MAX_VALUE; partition1.forEach((snippet1) => { partition2.forEach((snippet2) => { const distance = this.computeDistance(snippet1, snippet2); if (distance < lowestDistance) { lowes...
/** * Determine the lowest Levenshtein distance between elements of two partitions. * @param partition1 The first partition to compare. * @param partition2 The second partition to compare. * @returns The lowest Levenshtein distance between elements of the two partitions. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/snippetHelper.ts#L49-L60
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
Snippets.mergeMostSimilarPartitions
mergeMostSimilarPartitions(partitions: Partition[]): Partition[] { let index1 = -1; let index2 = -1; let mostSimilarDistance = Number.MAX_VALUE; for (let i = 0; i < partitions.length; i++) { for (let j = i + 1; j < partitions.length; j++) { const distance = this.comparePartitions(partition...
/** * Merge the two partitions with the lowest Levenshtein distance between them. * @param partitions The partitions. * @returns The partitions after merging. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/snippetHelper.ts#L67-L96
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
Snippets.selectSnippets
selectSnippets(snippets: Set<string>, n: number): Set<string> { // create partitions: initially, each snippet is in its own partition let partitions = this.createPartitions(snippets); // while we have too many partitions, merge the most similar ones while (partitions.length > n) { partitions = th...
/** * Select a set of representative snippets. This is done by grouping * the snippets into partitions so that the elements of each partition * are as similar as possible, and then selecting the smallest snippet * from each partition. * @param snippets The snippets to select representatives for. * @re...
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/src/snippetHelper.ts#L106-L129
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
createExpectedTests
function createExpectedTests(tests: string[], testFileName: string) { const expectedTests = new Set(); //add tests to expectedTests with index and fileName tests.forEach(function (test, index) { expectedTests.add({ fileName: testFileName, index: index, contents: dedent(test), }); }); ...
/** * helper function to create expected tests from an array of input tests * @param tests * @param testFileName * @returns Set of Test objects */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/test/editDistance.ts#L16-L28
a8becb94998343f3a11ad43f7d9a1705f874d50a
testpilot
github_2023
githubnext
typescript
runSimpleTest
async function runSimpleTest( fun: APIFunction, snippets: string[], prompts: { prompt: Prompt; tests: { completion: string; passes: boolean }[]; }[] ) { const model = new MockCompletionModel(true); const validator = new MockValidator(); const collector = new BaseTestResultColle...
/** * Test a simple test-generation scenario: for `fun` with snippets * `snippets`, we specify which completions the model supposedly returns for * each prompt, and we specify which tests are expected to pass. */
https://github.com/githubnext/testpilot/blob/a8becb94998343f3a11ad43f7d9a1705f874d50a/test/generateTests.ts#L51-L120
a8becb94998343f3a11ad43f7d9a1705f874d50a
zoplicate
github_2023
ChenglongMa
typescript
registerDevColumn
async function registerDevColumn() { const field = "Item ID"; await Zotero.ItemTreeManager.registerColumns({ pluginID: config.addonID, dataKey: field, label: "Item ID", dataProvider: (item: Zotero.Item, dataKey: string) => { return String(item.id) + " " + item.key; }, }); }
/** * Register a custom column for development purpose. */
https://github.com/ChenglongMa/zoplicate/blob/4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54/src/hooks.ts#L101-L111
4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54
zoplicate
github_2023
ChenglongMa
typescript
onNotify
async function onNotify(event: string, type: string, ids: number[] | string[], extraData: { [key: string]: any }) { if (!mainWindowLoaded) { debug("notify queue", event, type, ids, extraData); notifyQueue.push({ event, type, ids, extraData }); return; } // You can add your code to the corresponding `...
/** * This function is just an example of dispatcher for Notify events. * Any operations should be placed in a function to keep this function clear. * * Refer to: https://github.com/zotero/zotero/blob/main/chrome/content/zotero/xpcom/notifier.js */
https://github.com/ChenglongMa/zoplicate/blob/4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54/src/hooks.ts#L119-L173
4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54
zoplicate
github_2023
ChenglongMa
typescript
onPrefsEvent
async function onPrefsEvent(type: string, data: { [key: string]: any }) { switch (type) { case "load": await registerPrefsScripts(data.window); break; default: return; } }
/** * This function is just an example of dispatcher for Preference UI events. * Any operations should be placed in a function to keep this funcion clear. * @param type event type * @param data event data */
https://github.com/ChenglongMa/zoplicate/blob/4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54/src/hooks.ts#L181-L189
4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54
zoplicate
github_2023
ChenglongMa
typescript
NonDuplicatesDB.constructor
private constructor() { super(); }
// Define a batch size to avoid too many parameters
https://github.com/ChenglongMa/zoplicate/blob/4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54/src/db/nonDuplicates.ts#L7-L9
4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54
zoplicate
github_2023
ChenglongMa
typescript
DuplicateItems.key
get key(): number { return this._smallestItemID; }
/** * The group identifier of the duplicate items. */
https://github.com/ChenglongMa/zoplicate/blob/4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54/src/modules/duplicateItems.ts#L50-L52
4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54
zoplicate
github_2023
ChenglongMa
typescript
initLocale
function initLocale() { const l10n = new ( typeof Localization === "undefined" ? ztoolkit.getGlobal("Localization") : Localization )([`${config.addonRef}-addon.ftl`], true); addon.data.locale = { current: l10n, }; }
/** * Initialize locale data */
https://github.com/ChenglongMa/zoplicate/blob/4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54/src/utils/locale.ts#L8-L17
4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54
zoplicate
github_2023
ChenglongMa
typescript
isWindowAlive
function isWindowAlive(win?: Window) { return win && !Components.utils.isDeadWrapper(win) && !win.closed; }
/** * Check if the window is alive. * Useful to prevent opening duplicate windows. * @param win */
https://github.com/ChenglongMa/zoplicate/blob/4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54/src/utils/window.ts#L8-L10
4968a9f1d9cb8fdd0923a3b7226cc4b5f9ddfd54
modus
github_2023
hypermodeinc
typescript
onAddOrChange
const onAddOrChange = async (sourcePath: string) => { const filename = path.basename(sourcePath); const outputPath = path.join(appPath, "build", filename); try { runtimeOutput.pause(); this.log(); this.log(chalk.magentaBright(`Detected change in ${filename} file. Applying...`))...
// Whenever any of the env files change, copy to the build directory.
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/cli/src/commands/dev/index.ts#L218-L232
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
getMessageWithPad
function getMessageWithPad(formattedFirstMsg: string, formattedSecondMsg: string, firstPad: number, secondPad: number, firstMessageLength?: number): string { const padLeft = " ".repeat(firstPad); const actualFirstMsgLength = firstMessageLength ?? formattedFirstMsg.length; const padMiddle = " ".repeat(secondPad - ...
/** * Used for printing help messages like: * build Build a Modus app * dev Run a Modus app locally for development * * @param firstMessageLength The message can be ANSI escaped and have a length different from the actual string length */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/cli/src/custom/help.ts#L220-L226
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
fetchEndpoints
const fetchEndpoints = async () => { try { const response = await fetch("/explorer/api/endpoints"); const data = await response.json(); const origin = window.location.origin; const ep = data.map((endpoint: { path: string }) => { return endpoint.path.startsWith("/") ? `${...
// Fetch endpoints when component mounts
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/runtime/explorer/content/main.tsx#L74-L88
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
getCurrentTime
function getCurrentTime(tz: string): string { if (!localtime.isValidTimeZone(tz)) { return "error: invalid time zone"; } return localtime.nowInZone(tz); }
// The following functions are made available as "tools"
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/examples/textgeneration/assembly/toolcalling.ts#L127-L132
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
getUserTimeZone
function getUserTimeZone(): string { return localtime.getTimeZone(); }
/** * This function will return the default time zone for the user. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/examples/textgeneration/assembly/toolcalling.ts#L137-L139
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
getCurrentTimeInUserTimeZone
function getCurrentTimeInUserTimeZone(): string { const tz = localtime.getTimeZone(); if (tz === "") { return "error: cannot determine user's time zone"; } const time = localtime.nowInZone(tz); const result = <TimeAndZone>{ time, zone: tz }; return JSON.stringify(result); }
/** * This function combines the functionality of getCurrentTime and getUserTimeZone, * to reduce the number of tool calls required by the model. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/examples/textgeneration/assembly/toolcalling.ts#L145-L154
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Location.__INITIALIZE
__INITIALIZE(): this { return this; }
// serialized to a string in SQL format.
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/database.ts#L196-L198
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Point.__DESERIALIZE
__DESERIALIZE( data: string, key_start: i32, key_end: i32, value_start: i32, value_end: i32, ): boolean { if ( data.length < 7 || data.charAt(0) != '"' || data.charAt(data.length - 1) != '"' ) { return false; } const p = parsePointString(data.substring(1, d...
/* eslint-disable @typescript-eslint/no-unused-vars */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/database.ts#L205-L228
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Location.__DESERIALIZE
__DESERIALIZE( data: string, key_start: i32, key_end: i32, value_start: i32, value_end: i32, ): boolean { if ( data.length < 7 || data.charAt(0) != '"' || data.charAt(data.length - 1) != '"' ) { return false; } const p = parsePointString(data.substring(1, d...
/* eslint-disable @typescript-eslint/no-unused-vars */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/database.ts#L268-L291
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Query.withVariable
withVariable<T>(name: string, value: T): this { if (isString<T>()) { this.variables.set(name, value as string); return this; } else if (isInteger<T>()) { this.variables.set(name, JSON.stringify(value)); return this; } else if (isFloat<T>()) { this.variables.set(name, JSON.strin...
/** * Adds a variable to the query. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/dgraph.ts#L157-L175
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Mutation.constructor
constructor( public setJson: string = "", public delJson: string = "", public setNquads: string = "", public delNquads: string = "", public condition: string = "", ) {}
/** * Creates a new Mutation object. * @param setJson - JSON for setting data * @param delJson - JSON for deleting data * @param setNquads - RDF N-Quads for setting data * @param delNquads - RDF N-Quads for deleting data * @param condition - Condition for the mutation, as a DQL `@if` directive * ...
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/dgraph.ts#L193-L199
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Mutation.withSetJson
withSetJson(json: string): Mutation { this.setJson = json; return this; }
/** * Adds a JSON string for setting data to the mutation. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/dgraph.ts#L204-L207
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Mutation.withDelJson
withDelJson(json: string): Mutation { this.delJson = json; return this; }
/** * Adds a JSON string for deleting data to the mutation. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/dgraph.ts#L212-L215
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Mutation.withSetNquads
withSetNquads(nquads: string): Mutation { this.setNquads = nquads; return this; }
/** * Adds RDF N-Quads for setting data to the mutation. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/dgraph.ts#L220-L223
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Mutation.withDelNquads
withDelNquads(nquads: string): Mutation { this.delNquads = nquads; return this; }
/** * Adds RDF N-Quads for deleting data to the mutation. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/dgraph.ts#L228-L231
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Mutation.withCondition
withCondition(cond: string): Mutation { this.condition = cond; return this; }
/** * Adds a condition to the mutation, as a DQL `@if` directive. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/dgraph.ts#L236-L239
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
DynamicMap.__DESERIALIZE
__DESERIALIZE( data: string, key_start: i32, key_end: i32, value_start: i32, value_end: i32, ): boolean { // This would be ideal, but doesn't work: // this.data = JSON.parse<Map<string, JSON.Raw>>(data); // So instead, we have to parse the JSON manually. // // TODO: Update th...
/* eslint-disable @typescript-eslint/no-unused-vars */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/dynamicmap.ts#L92-L109
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Request.constructor
constructor(url: string, options: RequestOptions = new RequestOptions()) { this.url = url; this.method = options.method ? options.method!.toUpperCase() : "GET"; this.headers = options.headers; this.body = options.body ? options.body!.data : emptyArrayBuffer; }
/** * Creates a new `Request` instance. * @param url - The URL to send the request to. * @param options - The optional parameters for the request. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L77-L82
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Request.clone
static clone( request: Request, options: RequestOptions = new RequestOptions(), ): Request { const newOptions = { method: options.method || request.method, body: options.body || Content.from(request.body), } as RequestOptions; if (options.headers.entries().length > 0) { newOptio...
/** * Clones the request, replacing any previous options with the new options provided. * @param request - The request to clone. * @param options - The options to set on the new request. * @returns - A new `Request` instance. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L90-L106
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Response.bytes
bytes(): Uint8Array { return Uint8Array.wrap(this.body); }
/** * Returns the response body as an `Uint8Array`. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L111-L113
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Response.text
text(): string { return Content.from(this.body).text(); }
/** * Returns the response body as a text string. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L118-L120
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Response.json
json<T>(): T { return Content.from(this.body).json<T>(); }
/** * Deserializes the response body as JSON, and returns an object of type `T`. * @typeParam T - The type of object to return. * @returns An object of type `T` represented by the JSON in the response body. * @throws An error if the response body cannot be deserialized into the specified type. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L128-L130
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Content.from
static from<T>(value: T): Content { if (idof<T>() == idof<ArrayBuffer>()) { return new Content(value as ArrayBuffer); } else if (idof<T>() == idof<Uint8Array>()) { return new Content((value as Uint8Array).buffer); } else if (isString<T>()) { return new Content(String.UTF8.encode(value as s...
/** * Creates a new `Content` instance from the given value. * @param value - The value to create the content from. * Supported value types are: * - Binary content as a `ArrayBuffer` or `Uint8Array` * - Text content as a `string` * - A JSON-serializable object. * @returns A new `Content` instanc...
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L174-L184
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Content.bytes
bytes(): Uint8Array { return Uint8Array.wrap(this.data); }
/** * Returns the content as an `Uint8Array`. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L189-L191
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Content.text
text(): string { return String.UTF8.decode(this.data); }
/** * Returns the content as a text string. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L196-L198
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Content.json
json<T>(): T { return JSON.parse<T>(this.text()); }
/** * Deserializes the content as JSON, and returns an object of type `T`. * @typeParam T - The type of object to return. * @returns An object of type `T` represented by the JSON in the content. * @throws An error if the cannot be deserialized into the specified type. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L206-L208
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Response.ok
get ok(): bool { return this.status >= 200 && this.status < 300; }
/** * Returns whether the response status is OK (status code 2xx). */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L242-L244
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Headers.append
append(name: string, value: string): void { const key = name.toLowerCase(); if (this.data.has(key)) { this.data.get(key).values.push(value); } else { this.data.set(key, { name, values: [value] }); } }
/** * Appends a new header to the collection. * If a header with the same name already exists, the value is appended to the existing header. * @param name - The header name. * @param value - The header value. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L301-L308
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Headers.entries
entries(): string[][] { const entries: string[][] = []; const headers = this.data.values(); for (let i = 0; i < headers.length; i++) { const header = headers[i]; for (let j = 0; j < header.values.length; j++) { entries.push([header.name, header.values[j]]); } } return entri...
/** * Returns all of the headers. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L313-L323
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Headers.get
get(name: string): string | null { const key = name.toLowerCase(); if (!this.data.has(key)) { return null; } const header = this.data.get(key); return header.values.join(","); }
/** * Returns the value of the header with the given name. * If the header has multiple values, it returns them as a comma-separated string. * @param name - The header name. * @returns The header value, or `null` if the header does not exist. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L331-L339
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Headers.from
public static from<T>(value: T): Headers { switch (idof<T>()) { case idof<string[][]>(): { const headers = new Headers(); const arr = changetype<string[][]>(value); for (let i = 0; i < arr.length; i++) { for (let j = 1; j < arr[i].length; j++) { headers.append(arr...
/** * Creates a new `Headers` instance from a value of type `T`. * @param value - The value to create the headers from. * It can be a `string[][]`, a `Map<string, string>`, or a `Map<string, string[]>`. * @returns A new `Headers` instance. * @throws An error if the value type is not supported. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/http.ts#L348-L384
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
ModusModelFactory.getModel
getModel<T extends Model>(modelName: string): T { const info = hostGetModelInfo(modelName); if (utils.resultIsInvalid(info)) { throw new Error(`Model ${modelName} not found.`); } return instantiate<T>(info); }
/** * Gets a model object instance. * @param modelName The name of the model, as defined in the manifest. * @returns An instance of the model object, which can be used to interact with the model. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/models.ts#L40-L47
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
EagerResult.Keys
get Keys(): string[] { return this.keys; }
/** * @deprecated use `keys` (lowercase) instead */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/neo4j.ts#L58-L60
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
EagerResult.Records
get Records(): Record[] { return this.records; }
/** * @deprecated use `records` (lowercase) instead */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/neo4j.ts#L65-L67
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Record.Values
get Values(): string[] { return this.values; }
/** * @deprecated use `values` (lowercase) instead */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/neo4j.ts#L90-L92
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Record.get
get(key: string): string { for (let i = 0; i < this.Keys.length; i++) { if (this.Keys[i] == key) { return this.Values[i]; } } throw new Error("Key not found in record."); }
/** /* Get a value from a record at a given key as a JSON encoded string. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/neo4j.ts#L100-L107
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Record.getValue
getValue<T>(key: string): T { if ( isInteger<T>() || isFloat<T>() || isBoolean<T>() || isString<T>() || idof<T>() === idof<Node>() || idof<T>() === idof<Relationship>() || idof<T>() === idof<Path>() || idof<T>() === idof<DynamicMap>() || idof<T>() === idof<strin...
/** * Get a value from a record at a given key and cast or decode it to a specific type. */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/neo4j.ts#L112-L147
f2f0634dfc81c5a8fc99955b75ad581600de65d3
modus
github_2023
hypermodeinc
typescript
Record.__DESERIALIZE
__DESERIALIZE( data: string, key_start: i32, key_end: i32, value_start: i32, value_end: i32, ): boolean { throw new Error("Not implemented."); }
/* eslint-disable @typescript-eslint/no-unused-vars */
https://github.com/hypermodeinc/modus/blob/f2f0634dfc81c5a8fc99955b75ad581600de65d3/sdk/assemblyscript/src/assembly/neo4j.ts#L174-L182
f2f0634dfc81c5a8fc99955b75ad581600de65d3