1 | import { type MatchedRoute, type RadixRouter } from "radix3";
|
2 | import type { AkteFiles } from "./AkteFiles";
|
3 | import type { Awaitable, GlobalDataFn } from "./types";
|
4 | /** Akte app configuration object. */
|
5 | export type Config<TGlobalData> = {
|
6 | /**
|
7 | * Akte files this config is responsible for.
|
8 | *
|
9 | * Create them with {@link defineAkteFile} and {@link defineAkteFiles}.
|
10 | */
|
11 | files: AkteFiles<TGlobalData>[];
|
12 | /** Configuration related to Akte build process. */
|
13 | build?: {
|
14 | /**
|
15 | * Output directory for Akte build command.
|
16 | *
|
17 | * @remarks
|
18 | * This directory is overriden by the Akte Vite plugin when running Akte
|
19 | * through Vite.
|
20 | * @defaultValue `"dist"` for Akte build command, `".akte"` for Akte Vite plugin.
|
21 | */
|
22 | outDir?: string;
|
23 | };
|
24 | } & (TGlobalData extends Record<string | number | symbol, unknown> ? {
|
25 | /**
|
26 | * Global data retrieval function.
|
27 | *
|
28 | * The return value of this function is then shared with each Akte file.
|
29 | */
|
30 | globalData: GlobalDataFn<TGlobalData>;
|
31 | } : {
|
32 | /**
|
33 | * Global data retrieval function.
|
34 | *
|
35 | * The return value of this function is then shared with each Akte file.
|
36 | */
|
37 | globalData?: GlobalDataFn<TGlobalData>;
|
38 | });
|
39 | /** An Akte app, ready to be interacted with. */
|
40 | export declare class AkteApp<TGlobalData = unknown> {
|
41 | protected config: Config<TGlobalData>;
|
42 | constructor(config: Config<TGlobalData>);
|
43 | /**
|
44 | * Looks up the Akte file responsible for rendering the path.
|
45 | *
|
46 | * @param path - Path to lookup, e.g. "/foo"
|
47 | * @returns A match featuring the path, the path parameters if any, and the
|
48 | * Akte file.
|
49 | * @throws {for handling
NotFoundError} When no Akte file is found |
50 | * looked up path.
|
51 | * Programmatic API might still change not following SemVer.
|
52 | */
|
53 | lookup(path: string): MatchedRoute<{
|
54 | file: AkteFiles<TGlobalData>;
|
55 | }> & {
|
56 | path: string;
|
57 | };
|
58 | /**
|
59 | * Renders a match from {@link lookup}.
|
60 | *
|
61 | * @param match - Match to render.
|
62 | * @returns Rendered file.
|
63 | * @throws {@link NotFoundError} When the Akte file could not render the match
|
64 | * (404), with an optional `cause` attached to it for uncaught errors (500)
|
65 | * @experimental Programmatic API might still change not following SemVer.
|
66 | */
|
67 | render(match: MatchedRoute<{
|
68 | file: AkteFiles<TGlobalData>;
|
69 | }> & {
|
70 | path: string;
|
71 | }): Promise<string>;
|
72 | /**
|
73 | * Renders all Akte files.
|
74 | *
|
75 | * @returns Rendered files map.
|
76 | * @experimental Programmatic API might still change not following SemVer.
|
77 | */
|
78 | renderAll(): Promise<Record<string, string>>;
|
79 | /**
|
80 | * Writes a map of rendered Akte files to the specified `outDir`, or the app
|
81 | * specified one (defaults to `"dist"`).
|
82 | *
|
83 | * @param args - A map of rendered Akte files, and an optional `outDir`
|
84 | * @experimental Programmatic API might still change not following SemVer.
|
85 | */
|
86 | writeAll(args: {
|
87 | outDir?: string;
|
88 | files: Record<string, string>;
|
89 | }): Promise<void>;
|
90 | /**
|
91 | * Build (renders and write) all Akte files to the specified `outDir`, or the
|
92 | * app specified one (defaults to `"dist"`).
|
93 | *
|
94 | * @param args - An optional `outDir`
|
95 | * @returns Built files array.
|
96 | * @experimental Programmatic API might still change not following SemVer.
|
97 | */
|
98 | buildAll(args?: {
|
99 | outDir?: string;
|
100 | }): Promise<string[]>;
|
101 | /**
|
102 | * Akte caches all `globalData`, `data`, `bulkData` calls for performance.
|
103 | * This method can be used to clear the cache.
|
104 | *
|
105 | * @param alsoClearFileCache - Also clear cache on all registered Akte files.
|
106 | * @experimental Programmatic API might still change not following SemVer.
|
107 | */
|
108 | clearCache(alsoClearFileCache?: boolean): void;
|
109 | private _globalDataPromise;
|
110 | protected getGlobalDataPromise(): Awaitable<TGlobalData>;
|
111 | private _router;
|
112 | protected getRouter(): RadixRouter<{
|
113 | file: AkteFiles<TGlobalData>;
|
114 | }>;
|
115 | }
|