Skip to content

Commit ad768f2

Browse files
committed
duckdb aliases, platforms config
1 parent 27bc864 commit ad768f2

File tree

4 files changed

+59
-36
lines changed

4 files changed

+59
-36
lines changed

src/config.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {pathToFileURL} from "node:url";
88
import he from "he";
99
import type MarkdownIt from "markdown-it";
1010
import wrapAnsi from "wrap-ansi";
11-
import {DUCKDB_CORE_EXTENSIONS, DUCKDB_PLATFORMS} from "./duckdb.js";
11+
import {DUCKDB_CORE_ALIASES, DUCKDB_CORE_EXTENSIONS} from "./duckdb.js";
1212
import {visitFiles} from "./files.js";
1313
import {formatIsoDate, formatLocaleDate} from "./format.js";
1414
import type {FrontMatter} from "./frontMatter.js";
@@ -78,7 +78,7 @@ export interface SearchConfigSpec {
7878
}
7979

8080
export interface DuckDBConfig {
81-
platforms: Record<string, true>;
81+
platforms: {[name: string]: true};
8282
extensions: {[name: string]: DuckDBExtensionConfig};
8383
}
8484

@@ -522,21 +522,22 @@ export function stringOrNull(spec: unknown): string | null {
522522
return spec == null || spec === false ? null : String(spec);
523523
}
524524

525-
// TODO configure platforms?
526525
function normalizeDuckDB(spec: unknown): DuckDBConfig {
526+
const {mvp = true, eh = true} = spec?.["platforms"] ?? {};
527527
const extensions: {[name: string]: DuckDBExtensionConfig} = {};
528528
let extspec: Record<string, unknown> = spec?.["extensions"] ?? {};
529529
if (Array.isArray(extspec)) extspec = Object.fromEntries(extspec.map((name) => [name, {}]));
530530
if (extspec.json === undefined) extspec = {...extspec, json: false};
531531
if (extspec.parquet === undefined) extspec = {...extspec, parquet: false};
532-
for (const name in extspec) {
532+
for (let name in extspec) {
533533
if (!/^\w+$/.test(name)) throw new Error(`invalid extension: ${name}`);
534534
const vspec = extspec[name];
535535
if (vspec == null) continue;
536+
name = DUCKDB_CORE_ALIASES[name] ?? name;
536537
const {
537-
source = DUCKDB_CORE_EXTENSIONS.some(([n]) => n === name) ? "core" : "community",
538+
source = name in DUCKDB_CORE_EXTENSIONS ? "core" : "community",
538539
install = true,
539-
load = !DUCKDB_CORE_EXTENSIONS.find(([n]) => n === name)?.[1]
540+
load = !DUCKDB_CORE_EXTENSIONS[name]
540541
} = typeof vspec === "boolean"
541542
? {load: vspec}
542543
: typeof vspec === "string"
@@ -548,7 +549,15 @@ function normalizeDuckDB(spec: unknown): DuckDBConfig {
548549
load: Boolean(load)
549550
};
550551
}
551-
return {platforms: DUCKDB_PLATFORMS, extensions};
552+
return {
553+
platforms: Object.fromEntries(
554+
[
555+
["mvp", mvp],
556+
["eh", eh]
557+
].filter(([, enabled]) => enabled)
558+
),
559+
extensions
560+
};
552561
}
553562

554563
function normalizeDuckDBSource(source: string): string {

src/duckdb.ts

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,50 @@ const downloadRequests = new Map<string, Promise<string>>();
88

99
export const DUCKDB_WASM_VERSION = "1.29.0";
1010
export const DUCKDB_VERSION = "1.1.1";
11-
export const DUCKDB_PLATFORMS: DuckDBConfig["platforms"] = {eh: true, mvp: true};
1211

1312
// https://duckdb.org/docs/extensions/core_extensions.html
14-
export const DUCKDB_CORE_EXTENSIONS: [name: string, autoload: boolean][] = [
15-
["arrow", false],
16-
["autocomplete", true],
17-
["aws", true],
18-
["azure", true],
19-
["delta", true],
20-
["excel", true],
21-
["fts", true],
22-
["httpfs", true],
23-
["iceberg", false],
24-
["icu", true],
25-
["inet", true],
26-
["jemalloc", false],
27-
["json", true],
28-
["mysql", false],
29-
["parquet", true],
30-
["postgres", true],
31-
["spatial", false],
32-
["sqlite", true],
33-
["substrait", false],
34-
["tpcds", true],
35-
["tpch", true],
36-
["vss", false]
37-
];
13+
export const DUCKDB_CORE_ALIASES: Record<string, keyof typeof DUCKDB_CORE_EXTENSIONS> = {
14+
sqlite: "sqlite_scanner",
15+
sqlite3: "sqlite_scanner",
16+
postgres_scanner: "postgres",
17+
http: "httpfs",
18+
https: "httpfs",
19+
s3: "httpfs"
20+
} as const;
21+
22+
// https://duckdb.org/docs/extensions/core_extensions.html
23+
// https://duckdb.org/docs/api/wasm/extensions.html#list-of-officially-available-extensions
24+
export const DUCKDB_CORE_EXTENSIONS = {
25+
arrow: false,
26+
autocomplete: true,
27+
aws: true,
28+
azure: true,
29+
delta: true,
30+
excel: true,
31+
fts: true,
32+
httpfs: true,
33+
iceberg: false,
34+
icu: true,
35+
inet: true,
36+
jemalloc: false,
37+
json: true,
38+
mysql: false,
39+
parquet: true,
40+
postgres: true,
41+
spatial: false,
42+
sqlite_scanner: true,
43+
substrait: false,
44+
tpcds: true,
45+
tpch: true,
46+
vss: false
47+
} as const;
3848

3949
export async function getDuckDBManifest(
4050
{platforms, extensions}: DuckDBConfig,
4151
{root, aliases}: {root: string; aliases?: Map<string, string>}
4252
) {
4353
return {
44-
platforms,
54+
platforms: {mvp: "mvp" in platforms, eh: "eh" in platforms},
4555
extensions: Object.fromEntries(
4656
await Promise.all(
4757
Object.entries(extensions).map(([name, {install, load, source}]) =>

test/config-test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import assert from "node:assert";
22
import {resolve} from "node:path";
33
import MarkdownIt from "markdown-it";
4+
import type {DuckDBConfig} from "../src/config.js";
45
import {normalizeConfig as config, mergeToc, readConfig, setCurrentDate} from "../src/config.js";
56
import {LoaderResolver} from "../src/loader.js";
67

7-
const DUCKDB_DEFAULTS = {
8-
bundles: ["eh", "mvp"],
8+
const DUCKDB_DEFAULTS: DuckDBConfig = {
9+
platforms: {
10+
eh: true,
11+
mvp: true
12+
},
913
extensions: {
1014
json: {
1115
source: "https://extensions.duckdb.org/",

test/libraries-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("getImplicitStylesheets(imports)", () => {
5353
describe("getImplicitDownloads(imports)", () => {
5454
it("supports known imports", () => {
5555
assert.deepStrictEqual(
56-
getImplicitDownloads(["npm:@observablehq/duckdb"]),
56+
getImplicitDownloads(["npm:@observablehq/duckdb"], {extensions: {}, platforms: {mvp: true, eh: true}}),
5757
new Set([
5858
"npm:@duckdb/duckdb-wasm/dist/duckdb-mvp.wasm",
5959
"npm:@duckdb/duckdb-wasm/dist/duckdb-browser-mvp.worker.js",

0 commit comments

Comments
 (0)