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 | /**
|
43 | * Readonly array of {@link AkteFiles} registered within the app.
|
44 | *
|
45 | * @experimental Programmatic API might still change not following SemVer.
|
46 | */
|
47 | get files(): AkteFiles<TGlobalData>[];
|
48 | constructor(config: Config<TGlobalData>);
|
49 | /**
|
50 | * Looks up the Akte file responsible for rendering the path.
|
51 | *
|
52 | * @param path - Path to lookup, e.g. "/foo"
|
53 | * @returns A match featuring the path, the path parameters if any, and the
|
54 | * Akte file.
|
55 | * @throws {for handling
NotFoundError} When no Akte file is found |
56 | * looked up path.
|
57 | * Programmatic API might still change not following SemVer.
|
58 | */
|
59 | lookup(path: string): MatchedRoute<{
|
60 | file: AkteFiles<TGlobalData>;
|
61 | }> & {
|
62 | path: string;
|
63 | };
|
64 | /**
|
65 | * Renders a match from {@link lookup}.
|
66 | *
|
67 | * @param match - Match to render.
|
68 | * @returns Rendered file.
|
69 | * @throws {@link NotFoundError} When the Akte file could not render the match
|
70 | * (404), with an optional `cause` attached to it for uncaught errors (500)
|
71 | * @experimental Programmatic API might still change not following SemVer.
|
72 | */
|
73 | render(match: MatchedRoute<{
|
74 | file: AkteFiles<TGlobalData>;
|
75 | }> & {
|
76 | path: string;
|
77 | globalData?: TGlobalData;
|
78 | data?: unknown;
|
79 | }): Promise<string>;
|
80 | /**
|
81 | * Renders all Akte files.
|
82 | *
|
83 | * @returns Rendered files map.
|
84 | * @experimental Programmatic API might still change not following SemVer.
|
85 | */
|
86 | renderAll(): Promise<Record<string, string>>;
|
87 | /**
|
88 | * Writes a map of rendered Akte files to the specified `outDir`, or the app
|
89 | * specified one (defaults to `"dist"`).
|
90 | *
|
91 | * @param args - A map of rendered Akte files, and an optional `outDir`
|
92 | * @experimental Programmatic API might still change not following SemVer.
|
93 | */
|
94 | writeAll(args: {
|
95 | outDir?: string;
|
96 | files: Record<string, string>;
|
97 | }): Promise<void>;
|
98 | /**
|
99 | * Build (renders and write) all Akte files to the specified `outDir`, or the
|
100 | * app specified one (defaults to `"dist"`).
|
101 | *
|
102 | * @param args - An optional `outDir`
|
103 | * @returns Built files array.
|
104 | * @experimental Programmatic API might still change not following SemVer.
|
105 | */
|
106 | buildAll(args?: {
|
107 | outDir?: string;
|
108 | }): Promise<string[]>;
|
109 | /**
|
110 | * Akte caches all `globalData`, `data`, `bulkData` calls for performance.
|
111 | * This method can be used to clear the cache.
|
112 | *
|
113 | * @param alsoClearFileCache - Also clear cache on all registered Akte files.
|
114 | * @experimental Programmatic API might still change not following SemVer.
|
115 | */
|
116 | clearCache(alsoClearFileCache?: boolean): void;
|
117 | /**
|
118 | * Readonly cache of the app's definition `globalData` method.
|
119 | *
|
120 | * @experimental Programmatic API might still change not following SemVer.
|
121 | */
|
122 | get globalDataCache(): Awaitable<TGlobalData> | undefined;
|
123 | private _globalDataCache;
|
124 | /**
|
125 | * Retrieves data from the app's definition `globalData` method.
|
126 | *
|
127 | * @param context - Context to get global data with.
|
128 | * @returns Retrieved global data.
|
129 | * @remark Returned global data may come from cache.
|
130 | * @experimental Programmatic API might still change not following SemVer.
|
131 | */
|
132 | getGlobalData(): Awaitable<TGlobalData>;
|
133 | private _router;
|
134 | protected getRouter(): RadixRouter<{
|
135 | file: AkteFiles<TGlobalData>;
|
136 | }>;
|
137 | }
|