Skip to content

Commit 7037948

Browse files
author
Dominique Chuo
committed
better titles
1 parent e038629 commit 7037948

39 files changed

+153
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@monaco-editor/react": "^4.7.0",
15+
"@reifydb/core": "^0.2.0",
1516
"lucide-react": "^0.555.0",
1617
"monaco-editor": "^0.55.1",
1718
"react": "^19.2.0",

pnpm-lock.yaml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ui/executable-snippet.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import type { editor } from 'monaco-editor';
55
import { rqlLanguageDefinition, rqlLanguageConfiguration } from '@/lib/rql-language';
66
import { brutalistLightTheme } from '@/lib/monaco-themes';
77
import { cn } from '@/lib';
8-
import type { WasmDB } from '@/lib/wasm/reifydb_webassembly';
8+
import { createWasmDB, type WasmDB } from '@/lib/wasm-db';
99
import { seedCommand } from '@/lib/seed-data';
10+
import { UNDEFINED_VALUE, Value } from '@reifydb/core';
1011

1112
let languageRegistered = false;
1213

@@ -60,9 +61,8 @@ export function ExecutableSnippet({
6061

6162
async function initDb() {
6263
try {
63-
const { WasmDB } = await import('@/lib/wasm/reifydb_webassembly');
64+
const instance = await createWasmDB();
6465
if (mounted) {
65-
const instance = new WasmDB();
6666
// Run seed command to populate tables for documentation examples
6767
try {
6868
instance.command(seedCommand);
@@ -349,7 +349,10 @@ export function ExecutableSnippet({
349349

350350
function formatValue(value: unknown): string {
351351
if (value === null || value === undefined) {
352-
return 'null';
352+
return UNDEFINED_VALUE;
353+
}
354+
if (value instanceof Value) {
355+
return value.toString();
353356
}
354357
if (typeof value === 'object') {
355358
return JSON.stringify(value);

src/lib/wasm-db.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { decode } from '@reifydb/core';
2+
import type { WasmDB as RawWasmDB } from './wasm/reifydb_webassembly';
3+
4+
function transformToValueInstances(result: unknown): unknown {
5+
if (result === null || result === undefined) return result;
6+
if (typeof result !== 'object') return result;
7+
if (Array.isArray(result)) {
8+
return result.map(transformToValueInstances);
9+
}
10+
// Check if it's a TypeValuePair
11+
const obj = result as Record<string, unknown>;
12+
if ('type' in obj && 'value' in obj && Object.keys(obj).length === 2) {
13+
return decode(obj as { type: string; value: string });
14+
}
15+
// Transform object properties
16+
const transformed: Record<string, unknown> = {};
17+
for (const [key, value] of Object.entries(obj)) {
18+
transformed[key] = transformToValueInstances(value);
19+
}
20+
return transformed;
21+
}
22+
23+
export async function createWasmDB(): Promise<WasmDB> {
24+
const { WasmDB: RawDB } = await import('./wasm/reifydb_webassembly');
25+
return new WasmDB(new RawDB());
26+
}
27+
28+
export class WasmDB {
29+
constructor(private db: RawWasmDB) {}
30+
31+
command(rql: string): unknown {
32+
return transformToValueInstances(this.db.command(rql));
33+
}
34+
35+
query(rql: string): unknown {
36+
return transformToValueInstances(this.db.query(rql));
37+
}
38+
}

src/pages/docs/functions/date/add.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,21 @@ export function DateAddPage() {
7171

7272
<h3 className="text-lg font-bold mb-3">Calculate expiration date</h3>
7373
<ExecutableSnippet
74+
title="Calculate expiration date"
7475
initialCode={`from app.subscriptions
7576
extend { expires: date::add(start_date, days: 30) }`}
7677
/>
7778

7879
<h3 className="text-lg font-bold mt-6 mb-3">Add days to current date</h3>
7980
<ExecutableSnippet
81+
title="Add days to current date"
8082
initialCode={`from app.events
8183
extend { deadline: date::add(date::now(), days: 7) }`}
8284
/>
8385

8486
<h3 className="text-lg font-bold mt-6 mb-3">Subtract days</h3>
8587
<ExecutableSnippet
88+
title="Subtract days"
8689
initialCode={`from app.records
8790
extend { one_week_ago: date::add(date::now(), days: -7) }`}
8891
/>

src/pages/docs/functions/date/day.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ export function DateDayPage() {
6666

6767
<h3 className="text-lg font-bold mb-3">Filter by first day of month</h3>
6868
<ExecutableSnippet
69+
title="Filter by first day of month"
6970
initialCode={`from app.logs
7071
filter date::day(timestamp) == 1`}
7172
/>
7273

7374
<h3 className="text-lg font-bold mt-6 mb-3">Extract day component</h3>
7475
<ExecutableSnippet
76+
title="Extract day component"
7577
initialCode={`from app.events
7678
extend { day_of_month: date::day(created_at) }`}
7779
/>

src/pages/docs/functions/date/diff.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,21 @@ export function DateDiffPage() {
7676

7777
<h3 className="text-lg font-bold mb-3">Calculate days since creation</h3>
7878
<ExecutableSnippet
79+
title="Calculate days since creation"
7980
initialCode={`from app.orders
8081
extend { days_since: date::diff(date::now(), created_at, unit: "days") }`}
8182
/>
8283

8384
<h3 className="text-lg font-bold mt-6 mb-3">Filter by age</h3>
8485
<ExecutableSnippet
86+
title="Filter by age"
8587
initialCode={`from app.records
8688
filter date::diff(date::now(), created_at, unit: "days") > 30`}
8789
/>
8890

8991
<h3 className="text-lg font-bold mt-6 mb-3">Calculate hours between events</h3>
9092
<ExecutableSnippet
93+
title="Calculate hours between events"
9194
initialCode={`from app.sessions
9295
extend { duration_hours: date::diff(end_time, start_time, unit: "hours") }`}
9396
/>

src/pages/docs/functions/date/format.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,21 @@ export function DateFormatPage() {
7171

7272
<h3 className="text-lg font-bold mb-3">Format as ISO date</h3>
7373
<ExecutableSnippet
74+
title="Format as ISO date"
7475
initialCode={`from app.events
7576
extend { formatted: date::format(created_at, "%Y-%m-%d") }`}
7677
/>
7778

7879
<h3 className="text-lg font-bold mt-6 mb-3">Include time</h3>
7980
<ExecutableSnippet
81+
title="Include time"
8082
initialCode={`from app.logs
8183
extend { timestamp_str: date::format(timestamp, "%Y-%m-%d %H:%M:%S") }`}
8284
/>
8385

8486
<h3 className="text-lg font-bold mt-6 mb-3">Custom format</h3>
8587
<ExecutableSnippet
88+
title="Custom format"
8689
initialCode={`from app.orders
8790
extend { order_date: date::format(created_at, "%B %d, %Y") }`}
8891
/>

src/pages/docs/functions/date/hour.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export function DateHourPage() {
6666

6767
<h3 className="text-lg font-bold mb-3">Extract time components</h3>
6868
<ExecutableSnippet
69+
title="Extract time components"
6970
initialCode={`from app.events
7071
extend {
7172
hour: date::hour(timestamp),
@@ -75,6 +76,7 @@ extend {
7576

7677
<h3 className="text-lg font-bold mt-6 mb-3">Filter by business hours</h3>
7778
<ExecutableSnippet
79+
title="Filter by business hours"
7880
initialCode={`from app.requests
7981
filter date::hour(timestamp) >= 9 and date::hour(timestamp) < 17`}
8082
/>

src/pages/docs/functions/date/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function DateModuleOverviewPage() {
2121
<section>
2222
<h2 className="text-2xl font-black tracking-tight mb-4">Quick Example</h2>
2323
<ExecutableSnippet
24+
title="Quick Example"
2425
initialCode={`from app.events
2526
filter date::year(created_at) == 2024
2627
extend {

0 commit comments

Comments
 (0)