UNPKG

noodl-loader

Version:

Loader for noodl applications

88 lines (87 loc) 3.46 kB
import type { LiteralUnion } from 'type-fest'; import y from 'yaml'; import { createExtractor } from '../extractor'; import NoodlConfig from '../config'; import NoodlCadlEndpoint from '../cadlendpoint'; import FileSystemHost from '../file-system'; import type { ExtractOptions } from '../extractor'; import type { YAMLNode } from '../types'; import * as t from './loader-types'; export type LoadConfigOptions = { dir?: string; fs?: FileSystemHost; mode?: 'file' | 'url'; onCadlEndpointError?: (error: Error) => void; root?: Record<string, any>; } & Record<string, any>; export interface GetYmlFnOptions { config?: NoodlConfig; cadlEndpoint?: NoodlCadlEndpoint; dir?: string; fs?: FileSystemHost; mode?: t.LoadType; value: unknown; } export declare function getYml(options: GetYmlFnOptions): Promise<any>; declare class NoodlLoader extends t.AbstractLoader { #private; config: NoodlConfig; cadlEndpoint: NoodlCadlEndpoint; [Symbol.iterator](): Iterator<[name: string, node: any], any, any>; constructor(); get appKey(): string; get configKey(): string; get root(): { Config: NoodlConfig | null; Global: Record<string, YAMLNode>; } & { [key: string]: any; }; createURL(arg1: LiteralUnion<'config' | 'cadlEndpoint' | 'page', string>, arg2?: string): string; extract<As extends 'array' | 'object' = 'object'>(node: Parameters<ReturnType<typeof createExtractor>>[0], options?: ExtractOptions<As>): Promise<As extends "array" ? import("../extractor/asset").default<Record<string, any>>[] : Record<string, import("../extractor/asset").default<Record<string, any>>>>; reduce(callback: (acc: any, arg: [name: string, node: any], index: number, root: NoodlLoader['root']) => any, initialValue?: any): any; getLoadOptions<O extends Record<string, any> = Record<string, any>>(other?: O): { config: NoodlConfig; cadlEndpoint: NoodlCadlEndpoint; fs: FileSystemHost; languageSuffix: string; }; getState(): { /** * If languageSuffix is set, fetches to cadlMain/preload/pages will have the language code (taken from config) attached between the file name and extension. * @example * ```js * // When the languageSuffix is set to 'en" * const endpoint = 'https://public.aitmed.com/cadl/patd0.7d/BaseCSS_en.yml * ``` */ languageSuffix: string; }; /** * @param value Config, cadlEndpoint, preload name, page name, URL, filepath * @param options */ load(value?: string, options?: { dir?: string; mode?: 'url' | 'file'; includePreload?: boolean; includePages?: boolean; spread?: boolean; }): Promise<void>; loadConfig(yml: string, { dir, mode }?: { dir?: string; mode?: t.LoadType; }): Promise<void>; loadCadlEndpoint(arg1?: string | y.Document<y.Node<any>> | (Record<string, any> & { dir?: string; }) | null | undefined, arg2?: { dir?: string; fs?: FileSystemHost; mode?: 'file' | 'url'; }): Promise<void>; setAppKey(appKey: string): this; setConfigKey(configKey: string): this; setFileLanguageSuffix(languageSuffix: string): this; use(value: FileSystemHost): this; } export default NoodlLoader;