Open History to see the last commit
1/**
2 * Every code snippet in the guide, quoted from the app's source. Each one is
3 * a region of a real file (see `source-regions.ts`), read at build time with
4 * Vite's `?raw` imports, so editing the code updates the guide. A snippet
5 * whose region disappears fails the build's tests and throws on load.
6 */
7import clientSource from "@/api/client.ts?raw";
8import fakeServerSource from "@/api/fake-server.ts?raw";
9import collectionsSource from "@/db/collections.ts?raw";
10import mutationsSource from "@/db/mutations.ts?raw";
11import onDemandNotesSource from "@/db/on-demand-notes.ts?raw";
12import queriesSource from "@/db/queries.ts?raw";
13
14import { extractRegion } from "./source-regions";
15
16/** The files snippets are quoted from, by their path in the repo. */
17export const QUOTED_SOURCES = {
18 "src/api/client.ts": clientSource,
19 "src/api/fake-server.ts": fakeServerSource,
20 "src/db/collections.ts": collectionsSource,
21 "src/db/mutations.ts": mutationsSource,
22 "src/db/on-demand-notes.ts": onDemandNotesSource,
23 "src/db/queries.ts": queriesSource,
24} as const;
25
26export type QuotedSourcePath = keyof typeof QUOTED_SOURCES;
27
28export interface Snippet {
29 file: QuotedSourcePath;
30 region: string;
31 code: string;
32}
33
34function quote(file: QuotedSourcePath, region: string): Snippet {
35 return { file, region, code: extractRegion(QUOTED_SOURCES[file], region) };
36}
37
38export const SNIPPETS = {
39 notesCollection: quote("src/db/collections.ts", "notes-collection"),
40 saveNoteUpdates: quote("src/db/collections.ts", "save-note-updates"),
41 inFolder: quote("src/db/queries.ts", "in-folder"),
42 noteListQuery: quote("src/db/queries.ts", "note-list-query"),
43 noteCountsQuery: quote("src/db/queries.ts", "note-counts-query"),
44 noteStatsCollection: quote("src/db/queries.ts", "note-stats-collection"),
45 folderStatsQuery: quote("src/db/queries.ts", "folder-stats-query"),
46 renameFolder: quote("src/db/mutations.ts", "rename-folder"),
47 noteChanges: quote("src/db/mutations.ts", "note-changes"),
48 throwOnError: quote("src/api/client.ts", "throw-on-error"),
49 duplicateName: quote("src/api/fake-server.ts", "duplicate-name"),
50 onDemandCollection: quote("src/db/on-demand-notes.ts", "on-demand-collection"),
51 folderNotesQuery: quote("src/db/on-demand-notes.ts", "folder-notes-query"),
52} satisfies Record<string, Snippet>;