Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/evidence/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { buildEvidence, runEvidence, sourcesEvidence } from './programmatic.js';
6 changes: 4 additions & 2 deletions packages/evidence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
},
"files": [
"template",
"cli.js"
"cli.js",
"index.js",
"programmatic.js"
],
"devDependencies": {
"@evidence-dev/component-utilities": "workspace:*",
Expand Down Expand Up @@ -67,4 +69,4 @@
"engines": {
"node": ">=18"
}
}
}
67 changes: 67 additions & 0 deletions packages/evidence/programmatic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { cli } from '@evidence-dev/sdk/legacy-compat';

const restoreEnv = (originalEnv) => {
for (const key of Object.keys(process.env)) {
if (!(key in originalEnv)) delete process.env[key];
}
Object.assign(process.env, originalEnv);
};

/**
* Run an Evidence CLI command in-process without spawning a long-running server by default.
* @param {string[]} args
* @param {{cwd?: string, env?: Record<string, string>}} [options]
* @returns {Promise<void>}
*/
export const runEvidence = async (args = [], options = {}) => {
const originalArgv = process.argv;
const originalCwd = process.cwd();
const originalEnv = { ...process.env };

try {
if (options.cwd) process.chdir(options.cwd);
if (options.env) Object.assign(process.env, options.env);
process.argv = ['node', 'evidence', ...args];
await cli();
} finally {
process.argv = originalArgv;
restoreEnv(originalEnv);
if (process.cwd() !== originalCwd) process.chdir(originalCwd);
}
};

const addFlag = (args, name, value) => {
if (value === undefined || value === false || value === null) return;
args.push(`--${name}`);
if (value !== true) args.push(String(value));
};

/**
* Build an Evidence project to static output.
* @param {{strict?: boolean, debug?: boolean, cwd?: string, env?: Record<string, string>}} [options]
* @returns {Promise<void>}
*/
export const buildEvidence = async (options = {}) => {
const args = [options.strict ? 'build:strict' : 'build'];
addFlag(args, 'debug', options.debug);
await runEvidence(args, options);
};

/**
* Evaluate and materialize Evidence source queries.
* @param {{changed?: boolean, sources?: string | string[], queries?: string | string[], strict?: boolean, debug?: boolean, cwd?: string, env?: Record<string, string>}} [options]
* @returns {Promise<void>}
*/
export const sourcesEvidence = async (options = {}) => {
const args = ['sources'];
addFlag(args, 'changed', options.changed);
addFlag(args, 'strict', options.strict);
addFlag(args, 'debug', options.debug);

const sources = Array.isArray(options.sources) ? options.sources.join(',') : options.sources;
const queries = Array.isArray(options.queries) ? options.queries.join(',') : options.queries;
addFlag(args, 'sources', sources);
addFlag(args, 'queries', queries);

await runEvidence(args, options);
};
3 changes: 3 additions & 0 deletions packages/lib/sdk/src/plugins/datasources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ export * from './loadSources.js';
export * from './loadSourcePlugins.js';
export * from './writeSourceConfig.js';
export * from './cli/edit/Options.js';
export * from './Datasources.js';
export * from './evalSources.js';
export * from './updateManifest.js';
export { getDatasourceConfigAsEnvironmentVariables } from './loadSourceConfig.js';
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const entries = async () => {

/** @type {import("./$types").RequestHandler} */
export async function GET({ params: { route } }) {
if (route === '/settings') {
const normalizedRoute = route.replace(/^\/+/, '');

if (normalizedRoute === 'settings') {
const queries = [];
return json({ queries });
}
Expand All @@ -37,9 +39,18 @@ export async function GET({ params: { route } }) {
} else {
routesDir = path.join('.evidence', 'template', 'src', 'pages');
}
const routePath = path.join(process.cwd(), routesDir, route, '+page.md');

const content = await fs.readFile(routePath, 'utf8');
const routePath = path.join(process.cwd(), routesDir, normalizedRoute, '+page.md');

let content;
try {
content = await fs.readFile(routePath, 'utf8');
} catch (e) {
// Non-markdown routes (for example +page.svelte) do not have query metadata files.
if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {
return json({ queries: [] });
}
throw e;
}

const partialInjectedContent = preprocessor.injectPartials(content);
const queries = preprocessor.extractQueries(partialInjectedContent);
Expand Down
7 changes: 7 additions & 0 deletions sites/example-project/src/pages/dashboards/+layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Folder-level rendering policy for all dashboard routes.
// Sub-pages can still override these values in their own +page.js files.
const runtimeSSR = import.meta.env.EVIDENCE_RUNTIME_SSR === 'true';

export const ssr = true;
export const csr = true;
export const prerender = !runtimeSSR;
18 changes: 18 additions & 0 deletions sites/example-project/src/pages/dashboards/+page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Dashboards (SSR + CSR POC)
---

This folder is configured with:

- `ssr = true`
- `csr = true`
- `prerender = !import.meta.env.EVIDENCE_RUNTIME_SSR`

Set `EVIDENCE_RUNTIME_SSR=true` to make this folder runtime-rendered.

Without that env var, pages here are prerendered for static build compatibility.

## Pages

- [Realtime Dashboard](./realtime)
- [Monthly Snapshot (Per-page static override)](./monthly-snapshot)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Per-page override: this page is statically prerendered even though its parent
// dashboards folder defaults to runtime SSR.
export const prerender = true;
export const ssr = true;
export const csr = true;

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Monthly Snapshot (Static Override)
---

This page overrides its parent folder defaults with `prerender = true`.

Use this pattern for dashboards that update on a schedule (for example, nightly) while other dashboard routes stay runtime SSR.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('./$types').PageServerLoad} */
export const load = async ({ url }) => {
return {
pathname: url.pathname,
serverRenderedAt: new Date().toISOString()
};
};

30 changes: 30 additions & 0 deletions sites/example-project/src/pages/dashboards/realtime/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script>
import { onMount } from 'svelte';

/** @type {import('./$types').PageData} */
export let data;

let clientNow = new Date();
let hydratedAt = '';

onMount(() => {
hydratedAt = new Date().toISOString();
const timer = setInterval(() => {
clientNow = new Date();
}, 1000);
return () => clearInterval(timer);
});
</script>

<h1 class="markdown">Realtime Dashboard (Runtime SSR + CSR)</h1>
<p class="markdown">
This page is rendered on the server for each request and then hydrated in the browser.
</p>

<ul class="markdown">
<li><b>Route:</b> <code>{data.pathname}</code></li>
<li><b>Server rendered at:</b> <code>{data.serverRenderedAt}</code></li>
<li><b>Client hydrated at:</b> <code>{hydratedAt || 'hydrating...'}</code></li>
<li><b>Client clock (updates every second):</b> <code>{clientNow.toISOString()}</code></li>
</ul>

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const prerender = false;

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const prerender = false;

63 changes: 58 additions & 5 deletions sites/example-project/src/pages/types/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,64 @@ SELECT
# Nastier Test Values

```sql all_types
select
*
from test_all_types()
limit 2
select *
from (
select
'row_a'::varchar as varchar,
X'53514C' as blob,
true as bool,
12::tinyint as tinyint,
1200::smallint as smallint,
120000::int as int,
1200000000::bigint as bigint,
1234567890123456789::hugeint as hugeint,
200::utinyint as utinyint,
50000::usmallint as usmallint,
3000000000::uinteger as uint,
9000000000000000000::ubigint as ubigint,
1.25::float as float,
2.5::double as double,
date '2024-01-01' as date,
timestamp '2024-01-01 10:11:12' as timestamp,
cast('2024-01-01 10:11:12' as timestamp_s) as timestamp_s,
cast('2024-01-01 10:11:12' as timestamp_ms) as timestamp_ms,
cast('2024-01-01 10:11:12' as timestamp_ns) as timestamp_ns,
cast('2024-01-01 10:11:12+00:00' as timestamp with time zone) as timestamp_tz,
cast('10:11:12' as time) as time,
cast('10:11:12+00:00' as time with time zone) as time_tz,
cast(3.1 as decimal(4,1)) as dec_4_1,
cast(3.1415 as decimal(9,4)) as dec_9_4,
cast(3.141592 as decimal(18,6)) as dec_18_6,
cast(3.1415926535 as decimal(38,10)) as dec38_10
union all
select
'row_b'::varchar as varchar,
X'414243' as blob,
false as bool,
24::tinyint as tinyint,
2400::smallint as smallint,
240000::int as int,
2400000000::bigint as bigint,
2234567890123456789::hugeint as hugeint,
150::utinyint as utinyint,
45000::usmallint as usmallint,
2000000000::uinteger as uint,
8000000000000000000::ubigint as ubigint,
2.25::float as float,
3.5::double as double,
date '2024-01-02' as date,
timestamp '2024-01-02 10:11:12' as timestamp,
cast('2024-01-02 10:11:12' as timestamp_s) as timestamp_s,
cast('2024-01-02 10:11:12' as timestamp_ms) as timestamp_ms,
cast('2024-01-02 10:11:12' as timestamp_ns) as timestamp_ns,
cast('2024-01-02 10:11:12+00:00' as timestamp with time zone) as timestamp_tz,
cast('11:11:12' as time) as time,
cast('11:11:12+00:00' as time with time zone) as time_tz,
cast(4.1 as decimal(4,1)) as dec_4_1,
cast(4.1415 as decimal(9,4)) as dec_9_4,
cast(4.141592 as decimal(18,6)) as dec_18_6,
cast(4.1415926535 as decimal(38,10)) as dec38_10
) t
```

<DataTable data={all_types}/>
Expand Down Expand Up @@ -341,4 +395,3 @@ My dec(18,6) is **<Value data={all_types} column="dec_18_6" row=0/>**
/>

My decimal(38,10) is **<Value data={all_types} column="dec38_10" row=0/>**

15 changes: 6 additions & 9 deletions sites/example-project/src/pages/ui-components/button/+page.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<script>
import { Button } from '@evidence-dev/core-components'
import {Pencil} from '@evidence-dev/component-utilities/icons'

const icons = [
{ iconPosition: "left", icon: Pencil },
{ iconPosition: "right", icon: Pencil },
{ iconPosition: "hidden", icon: undefined }
{ iconPosition: "right", icon: undefined }
]
const variants = ["success", "info", "warn", "error"]
const sizes = ["sm", "base", "lg"]
const variants = ["default", "primary", "destructive", "muted", "ghost", "link"]
const sizes = ["default", "lg", "xl"]

</script>

Expand All @@ -16,25 +17,21 @@
<table class="w-full border border-black">
<tr>
<th class="pl-4 py-4">Variant</th>
<th class="bg-gray-200">Outlined</th>
<th>Size</th>
<th class="bg-gray-200">Icon Position</th>
<th></th>
</tr>

{#each variants as variant}
{#each [false, true] as outline}
{#each sizes as size}
{#each icons as {iconPosition, icon}}
<tr class="odd:bg-gray-200 border border-gray-700 group text-center">
<td class="pl-4 h-16">{variant}</td>
<td class="group-odd:bg-gray-400 group-even:bg-gray-200">{outline}</td>
<td>{size}</td>
<td class="group-odd:bg-gray-400 group-even:bg-gray-200">{iconPosition}</td>
<td class="pr-4"><div class="flex justify-center items-middle h-full"><Button {size} {variant} {iconPosition} {icon} {outline}>Click Me!</Button></div></td>
<td class="pr-4"><div class="flex justify-center items-middle h-full"><Button {size} {variant} {iconPosition} {icon}>Click Me!</Button></div></td>
</tr>
{/each}
{/each}
{/each}
{/each}
</table>
</table>
Loading