MCPcopy Create free account
hub / github.com/blacksmithgu/datacore / loadUncached

Method loadUncached

src/api/script-cache.ts:100–123  ·  view source on GitHub ↗

Load a script, directly bypassing the cache.

(
        path: string | Link,
        context: Record<string, unknown>
    )

Source from the content-addressed store, hash-verified

98
99 /** Load a script, directly bypassing the cache. */
100 private async loadUncached(
101 path: string | Link,
102 context: Record<string, unknown>
103 ): Promise<Result<unknown, string>> {
104 const maybeSource = await this.resolveSource(path);
105 if (!maybeSource.successful) return maybeSource;
106
107 // Transpile to vanilla javascript first...
108 const { code, language } = maybeSource.value;
109 let basic;
110 try {
111 basic = transpile(code, language);
112 } catch (error) {
113 return Result.failure(`Failed to import ${path.toString()} while transpiling from ${language}: ${error}`);
114 }
115
116 // Then finally execute the script to 'load' it.
117 const finalContext = Object.assign({ h: h, Fragment: Fragment }, context);
118 try {
119 return Result.success(await asyncEvalInContext(basic, finalContext));
120 } catch (error) {
121 return Result.failure(`Failed to execute script '${path.toString()}': ${error}`);
122 }
123 }
124
125 /** Normalize a path or link to a textual path. */
126 private pathkey(path: string | Link): string {

Callers 1

loadMethod · 0.95

Calls 4

resolveSourceMethod · 0.95
transpileFunction · 0.90
asyncEvalInContextFunction · 0.90
toStringMethod · 0.45

Tested by

no test coverage detected