-
Notifications
You must be signed in to change notification settings - Fork 0
API Host IScriptSourceResolver
自定义脚本加载扩展点
Custom script-loading extension point
实现 IScriptSourceResolver 可以从数据库、对象存储、嵌入资源或虚拟目录加载脚本。必须使用稳定的规范化引用,并在解析相对 import/include 时保留 importer 上下文。
Implement
IScriptSourceResolverto load scripts from a database, object storage, embedded resources, or virtual directories. Use stable normalized references and retainimportercontext when resolving relative imports/includes.
Returns
此 Resolver 管理的规范化根。
Normalized root managed by this resolver.
public string Root => "mem://tenant-a/";Parameters:
-
importer
当前导入者或null(入口)。Importing source or
null(entry). -
requestedPath
原始请求路径。Raw requested path.
-
context
解析上下文。Resolution context.
-
cancellationToken
可选取消令牌。Optional cancellation token.
Returns
稳定 ScriptSourceReference 或 null。
Stable
ScriptSourceReferenceornull.
public ValueTask<ScriptSourceReference?> ResolveAsync(
ScriptSourceReference? importer,
string requestedPath,
ScriptResolveContext context,
CancellationToken cancellationToken = default)
{
var fullPath = importer is null ? Root + requestedPath : Root + requestedPath;
return ValueTask.FromResult<ScriptSourceReference?>(new ScriptSourceReference(Root, fullPath));
}Parameters:
-
reference
已解析引用。Resolved reference.
-
cancellationToken
可选取消令牌。Optional cancellation token.
Returns
对应 ScriptSource。
Matching
ScriptSource.
public ValueTask<ScriptSource> GetSourceAsync(
ScriptSourceReference reference,
CancellationToken cancellationToken = default) =>
ValueTask.FromResult<ScriptSource>(new MemorySource(Root, reference.FullPath, "@module(MAIN);"));Parameters:
-
query
枚举过滤条件。Enumeration filter.
-
cancellationToken
可选取消令牌。Optional cancellation token.
Returns
BuildAsync() 可见的异步源码序列。
Async source sequence visible to
BuildAsync().
public async IAsyncEnumerable<ScriptSource> GetAllSourcesAsync(
ScriptSourceQuery query,
[System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
{
yield return new MemorySource(Root, Root + "main.as", "@module(MAIN);");
await Task.CompletedTask;
}示例只展示接口形状;生产 Resolver 必须规范化路径、正确处理取消并确保 GetSourceAsync 根据 reference.BaseDirectory 路由。
the examples show interface shape only; a production resolver must normalize paths, honor cancellation, and route
GetSourceAsyncbyreference.BaseDirectory.
AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License