import { DataFile } from '@comyata/fe/DataFile'; import { DataFileRegistry } from '@comyata/fe/DataFileRegistry'; import { Importers } from '@comyata/fe/Importers'; import { Parser } from '@comyata/run/Parser'; import { DataNode, IDataNode } from '@comyata/run/DataNode'; import { ComputeStats, runtime, IComputeStatsBase, NodeRuntimeBaggage, NodeRuntimeBaggageComplete, NodeComputeEngines, ComputeFn } from '@comyata/run/Runtime'; export interface Resolver { id: string; /** * @todo most pure-loaders shouldn't need to specify resolveRelative, * but only with real-data, for filtering/sorting, (and not just a string as $load arg) something like 'genFileIdFromArgs" would make sense */ scopes: string[]; resolveDirectory?: (baseUrl: string) => ResolveContext; resolveFile: (fileUrl: string) => FileResolveContext; } export interface ResolveContext { /** * @todo maybe support a Symbol based id, to distinguish importers with same ID * @todo make import context required? would make the in-memory files complexer - or depending on their actual importer */ importer?: string; resolveRelative?: ((relPath: string) => string); } export interface FileResolveContext extends ResolveContext { load: () => Promise | unknown; } export interface FileComputeStats extends IComputeStatsBase { step: 'computeFile'; file: string; stats: (FileComputeStats | ComputeStats)[]; cached?: 0 | 1 | 2; usages?: Map>; } export type ImportContext = ResolveContext | FileResolveContext; export type RuntimeContext = { registry: DataFileRegistry; /** * Either an object containing the computed result for an file in the current run, * or a subscriber function if currently already running computations, which resolves with the computed data. * * Used as a runtime cache, as each file will always be executed with the same "context" the resulted computations are expected to be stable within one run. * This guarantees that multiple `$import/$load` on the same URL will always have the same data inside a single run. */ fileEvals: Map, requestingNodesChain: Set) => Promise)>; fileEvalsAwaiter: Map>; fileListener: Map void)[]>; /** * map which DataFile is used by which DataFile in which DataNode */ usages: Map>>; }; export interface FileRuntimeBaggage extends NodeRuntimeBaggage { dataFile: DataFile; filesChain: Set>; computeStats: FileComputeStats; runtimeContext: RuntimeContext; fileEngine: Pick, 'run' | 'fetchFile'>; } export type FileComputeFn = FileRuntimeBaggage> = ComputeFn>; export type FileComputeFn2 = (dataNode: TNode, context: C, parentData: unknown[], runtimeBaggage: FileRuntimeBaggage & NodeRuntimeBaggageComplete) => Promise; type FileComputeEngines = FileRuntimeBaggage> = NodeComputeEngines; declare class SubscribeMap extends Map { private readonly listeners; set(key: K, value: V): this; delete(key: K): boolean; clear(): void; onAdd(cb: (key: K, value: V) => void): () => void; onDelete(cb: (deletedKey: K) => void): () => void; } export declare class FileEngine { readonly parser: Parser; readonly files: SubscribeMap>>; readonly compute: FileComputeEngines>; readonly processorOptions: Parameters[3]; private readonly importer; constructor({ nodes, compute, importer, processorOptions, parserOptions, }: { nodes: TNode[]; compute: FileComputeEngines>; importer?: Importers; processorOptions?: Parameters[3]; parserOptions?: Partial['options']>; }); /** * @todo risky method, only use outside of computations/runs, to not accidentally access the wrong files cache, * safe to use outside of runs */ contextOf(contextBaseUrl: string): ResolveContext; /** * @todo maybe move into registry? * @todo risky method, only use outside of computations/runs, to not accidentally access the wrong files cache; * safe to use outside of runs */ fileRef(file: string, importContext?: ImportContext): DataFile>; register(id: string, objOrEval: unknown, importContext?: ImportContext): DataFile>; private newFile; fetchFile(dataFile: DataFile>, registry: DataFileRegistry>, statsList?: any[]): Promise; run(dataFile: DataFile>, context?: unknown, runtimeContext?: RuntimeContext>, { filesChain, nodesChain, ...baggage }?: { filesChain?: Set>>; nodesChain?: Set>; abort?: AbortSignal; }): Promise<[unknown, FileComputeStats, RuntimeContext>]>; } export {};