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";
13import realtimeNotesSource from "@/db/realtime-notes.ts?raw";
14
15import { extractCodeFence, extractRegion } from "./source-regions";
16import neonReadme from "./vendor/neon-realtime-tanstack-0.1.1-README.md?raw";
17
18/** The files snippets are quoted from, by their path in the repo. */
19export const QUOTED_SOURCES = {
20 "src/api/client.ts": clientSource,
21 "src/api/fake-server.ts": fakeServerSource,
22 "src/db/collections.ts": collectionsSource,
23 "src/db/mutations.ts": mutationsSource,
24 "src/db/on-demand-notes.ts": onDemandNotesSource,
25 "src/db/queries.ts": queriesSource,
26 "src/db/realtime-notes.ts": realtimeNotesSource,
27} as const;
28
29export type QuotedSourcePath = keyof typeof QUOTED_SOURCES;
30
31export interface Snippet {
32 /** Where the code is from, shown above it. */
33 file: string;
34 code: string;
35}
36
37export interface SourceRegionSnippet extends Snippet {
38 file: QuotedSourcePath;
39 region: string;
40}
41
42function quote(file: QuotedSourcePath, region: string): SourceRegionSnippet {
43 return { file, region, code: extractRegion(QUOTED_SOURCES[file], region) };
44}
45
46export const SNIPPETS = {
47 notesCollection: quote("src/db/collections.ts", "notes-collection"),
48 saveNoteUpdates: quote("src/db/collections.ts", "save-note-updates"),
49 inFolder: quote("src/db/queries.ts", "in-folder"),
50 noteListQuery: quote("src/db/queries.ts", "note-list-query"),
51 noteCountsQuery: quote("src/db/queries.ts", "note-counts-query"),
52 noteStatsCollection: quote("src/db/queries.ts", "note-stats-collection"),
53 folderStatsQuery: quote("src/db/queries.ts", "folder-stats-query"),
54 renameFolder: quote("src/db/mutations.ts", "rename-folder"),
55 noteChanges: quote("src/db/mutations.ts", "note-changes"),
56 throwOnError: quote("src/api/client.ts", "throw-on-error"),
57 duplicateName: quote("src/api/fake-server.ts", "duplicate-name"),
58 onDemandCollection: quote("src/db/on-demand-notes.ts", "on-demand-collection"),
59 folderNotesQuery: quote("src/db/on-demand-notes.ts", "folder-notes-query"),
60 realtimeNotesCollection: quote("src/db/realtime-notes.ts", "realtime-notes-collection"),
61 syncRun: quote("src/db/realtime-notes.ts", "sync-run"),
62 livePatchNote: quote("src/api/fake-server.ts", "live-patch-note"),
63} satisfies Record<string, SourceRegionSnippet>;
64
65/**
66 * The Neon Realtime deep dive quotes the package's own README (a copy of the
67 * one published with `@neon/realtime-tanstack` 0.1.1, in `vendor/`) for the
68 * real API, and `db/realtime-notes.ts` for the simulation it demos: the
69 * package isn't installed here (see that page).
70 */
71export const NEON_README_SNIPPETS = {
72 collection: {
73 file: "@neon/realtime-tanstack 0.1.1 · README",
74 code: extractCodeFence(neonReadme, "ts", 0),
75 },
76 awaitTxId: {
77 file: "@neon/realtime-tanstack 0.1.1 · README",
78 code: extractCodeFence(neonReadme, "ts", 1),
79 },
80} satisfies Record<string, Snippet>;