@gscdump/engine-duckdb-wasm 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -43
- package/dist/index.mjs +4 -46
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Assume, DrizzleConfig, entityKind } from "drizzle-orm";
|
|
2
2
|
import { PgDatabase, PgDialect, PgPreparedQuery, PgQueryResultHKT, PgSession } from "drizzle-orm/pg-core";
|
|
3
|
-
import { QueryRow, SqlQuerySource, pgResolverAdapter as browserResolverAdapter } from "@gscdump/engine/resolver";
|
|
4
3
|
import { DrizzleSchema as Schema, countries, devices, drizzleSchema as schema, keywords, page_keywords, pages } from "@gscdump/engine/schema";
|
|
5
4
|
import * as _$_gscdump_engine_scope0 from "@gscdump/engine/scope";
|
|
6
5
|
import { ScopedRunnerOptions, TableScope } from "@gscdump/engine/scope";
|
|
@@ -26,13 +25,6 @@ interface DuckDBWasmDrizzleDatabase<TSchema extends Record<string, unknown> = Re
|
|
|
26
25
|
$client: Promise<DuckDBWasmClient>;
|
|
27
26
|
}
|
|
28
27
|
declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(client: Promise<DuckDBWasmClient> | DuckDBWasmClient, config?: DrizzleConfig<TSchema>): DuckDBWasmDrizzleDatabase<TSchema>;
|
|
29
|
-
interface BrowserQueryRunner {
|
|
30
|
-
query: (sql: string, params?: unknown[]) => Promise<QueryRow[]>;
|
|
31
|
-
}
|
|
32
|
-
interface EngineConfig {
|
|
33
|
-
runner: BrowserQueryRunner;
|
|
34
|
-
}
|
|
35
|
-
declare function createEngine(config: EngineConfig): SqlQuerySource;
|
|
36
28
|
interface InsightRunnerOptions {
|
|
37
29
|
db: AsyncDuckDB;
|
|
38
30
|
conn: AsyncDuckDBConnection;
|
|
@@ -142,15 +134,6 @@ interface AttachParquetUrlTablesOptions {
|
|
|
142
134
|
total: number;
|
|
143
135
|
}) => void;
|
|
144
136
|
}
|
|
145
|
-
interface AttachSingleTableOptions {
|
|
146
|
-
db: AsyncDuckDB;
|
|
147
|
-
conn: AsyncDuckDBConnection;
|
|
148
|
-
table: string;
|
|
149
|
-
urls: string[];
|
|
150
|
-
fetch?: typeof fetch;
|
|
151
|
-
schema?: string;
|
|
152
|
-
fetchInit?: RequestInit;
|
|
153
|
-
}
|
|
154
137
|
/**
|
|
155
138
|
* Handle returned from {@link attachParquetUrlTables}. Lets callers detach
|
|
156
139
|
* the created views (for lazy re-attach on a new manifest version) or cheap-
|
|
@@ -188,37 +171,12 @@ interface BrowserAnalysisRuntime {
|
|
|
188
171
|
setAttachedTables: (tables: readonly string[]) => void;
|
|
189
172
|
close: () => Promise<void>;
|
|
190
173
|
}
|
|
191
|
-
/**
|
|
192
|
-
* Build a `DuckDBBundles` map from a single base URL hosting the standard
|
|
193
|
-
* DuckDB-WASM asset set (matches the names jsDelivr + `@duckdb/duckdb-wasm`
|
|
194
|
-
* ship). Callers pointing at a Worker / R2 / self-hosted origin can pass
|
|
195
|
-
* just the origin instead of duplicating the URL layout across apps.
|
|
196
|
-
*
|
|
197
|
-
* Omits `coi` (pthread) by default; most hosts don't serve the
|
|
198
|
-
* cross-origin-isolation headers needed to use it and requesting a missing
|
|
199
|
-
* asset fails bundle selection on Safari/Firefox.
|
|
200
|
-
*/
|
|
201
|
-
declare function createDuckDBBundlesFromBase(baseUrl: string, options?: {
|
|
202
|
-
includeCoi?: boolean;
|
|
203
|
-
}): DuckDBBundles;
|
|
204
174
|
declare function bootDuckDBWasm(options?: BootDuckDBWasmOptions): Promise<DuckDBWasmBootResult>;
|
|
205
175
|
declare function attachParquetTables(options: AttachParquetTablesOptions): Promise<void>;
|
|
206
176
|
declare function attachParquetUrlTables(options: AttachParquetUrlTablesOptions): Promise<AttachedTablesHandle>;
|
|
207
|
-
/**
|
|
208
|
-
* Incremental attach — fetch + register a single table's URLs and create the
|
|
209
|
-
* view, without touching any other table. Use this for lazy attach when a
|
|
210
|
-
* page only needs one of several available tables.
|
|
211
|
-
*/
|
|
212
|
-
declare function attachSingleTable(options: AttachSingleTableOptions): Promise<void>;
|
|
213
|
-
/**
|
|
214
|
-
* List the views currently attached under `schema` via DuckDB's
|
|
215
|
-
* `information_schema`. Lets callers decide whether to call
|
|
216
|
-
* `attachSingleTable` before each query without guessing at state.
|
|
217
|
-
*/
|
|
218
|
-
declare function listAttachedTables(conn: AsyncDuckDBConnection, schema?: string): Promise<string[]>;
|
|
219
177
|
declare function createBrowserAnalysisRuntime(boot: DuckDBWasmBootResult, options?: {
|
|
220
178
|
schema?: string;
|
|
221
179
|
version?: number | string;
|
|
222
180
|
attachedTables?: readonly string[];
|
|
223
181
|
}): BrowserAnalysisRuntime;
|
|
224
|
-
export { type AnalyzeResult, type AttachParquetTablesOptions, type AttachParquetUrlTablesOptions, type
|
|
182
|
+
export { type AnalyzeResult, type AttachParquetTablesOptions, type AttachParquetUrlTablesOptions, type AttachedTablesHandle, type BootDuckDBWasmOptions, type BrowserAnalysisRuntime, type BrowserParquetFile, type BrowserParquetTable, type BrowserParquetUrlTable, type ComparisonMode, type DuckDBWasmBootResult, type DuckDBWasmClient, DuckDBWasmDatabase, type DuckDBWasmDrizzleDatabase, type InsightRunner, type InsightRunnerOptions, type QueryResult, type ResolveWindowOptions, type ResolvedWindow, type Schema, type ScopedRunnerOptions, type StrikingMomentumOptions, type StrikingMomentumRow, type TableScope, type WindowPreset, attachParquetTables, attachParquetUrlTables, bootDuckDBWasm, countries, createBrowserAnalysisRuntime, createClient, createInsightRunner, devices, drizzle, keywords, mergeScope, page_keywords, pages, resolveWindow, schema, scopeFor, strikingMomentum };
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { arrowToRows } from "@gscdump/engine/arrow";
|
|
2
2
|
import { DefaultLogger, NoopLogger, createTableRelationsHelpers, entityKind, extractTablesRelationalConfig, fillPlaceholders, sql } from "drizzle-orm";
|
|
3
3
|
import { PgDatabase, PgDialect, PgPreparedQuery, PgSession } from "drizzle-orm/pg-core";
|
|
4
|
-
import { createSqlQuerySource, pgResolverAdapter as browserResolverAdapter } from "@gscdump/engine/resolver";
|
|
5
4
|
import { toIsoDate } from "gscdump";
|
|
6
5
|
import { countries, devices, drizzleSchema as schema, keywords, page_keywords, pages } from "@gscdump/engine/schema";
|
|
7
6
|
import { createScopedHelpers } from "@gscdump/engine/scope";
|
|
8
7
|
import { runAnalyzerFromSource } from "@gscdump/engine/analyzer";
|
|
8
|
+
import { pgResolverAdapter } from "@gscdump/engine/resolver";
|
|
9
9
|
import { createAttachedTableSource } from "@gscdump/engine/source";
|
|
10
10
|
import { sqlEscape } from "@gscdump/engine/sql";
|
|
11
11
|
import { resolveWindow } from "@gscdump/engine/period";
|
|
@@ -89,15 +89,6 @@ function drizzle(client, config = {}) {
|
|
|
89
89
|
db.$client = clientPromise;
|
|
90
90
|
return db;
|
|
91
91
|
}
|
|
92
|
-
function createEngine(config) {
|
|
93
|
-
const { runner } = config;
|
|
94
|
-
return createSqlQuerySource({
|
|
95
|
-
name: "browser",
|
|
96
|
-
adapter: browserResolverAdapter,
|
|
97
|
-
execute: (sql, params) => runner.query(sql, params),
|
|
98
|
-
extraCapabilities: { attachedTables: true }
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
92
|
async function strikingMomentum(runner, opts = {}) {
|
|
102
93
|
const windowDays = opts.windowDays ?? 90;
|
|
103
94
|
const anchor = opts.anchor ?? toIsoDate(/* @__PURE__ */ new Date());
|
|
@@ -178,25 +169,6 @@ function fileName(table, index, provided) {
|
|
|
178
169
|
function readParquetViewSql(schema, table, files) {
|
|
179
170
|
return `CREATE OR REPLACE VIEW ${schema}.${table} AS SELECT * FROM read_parquet([${files.map((name) => `'${sqlEscape(name)}'`).join(", ")}], union_by_name = true)`;
|
|
180
171
|
}
|
|
181
|
-
function createDuckDBBundlesFromBase(baseUrl, options = {}) {
|
|
182
|
-
const base = baseUrl.replace(/\/+$/, "");
|
|
183
|
-
const bundles = {
|
|
184
|
-
mvp: {
|
|
185
|
-
mainModule: `${base}/duckdb-mvp.wasm`,
|
|
186
|
-
mainWorker: `${base}/duckdb-browser-mvp.worker.js`
|
|
187
|
-
},
|
|
188
|
-
eh: {
|
|
189
|
-
mainModule: `${base}/duckdb-eh.wasm`,
|
|
190
|
-
mainWorker: `${base}/duckdb-browser-eh.worker.js`
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
if (options.includeCoi) bundles.coi = {
|
|
194
|
-
mainModule: `${base}/duckdb-coi.wasm`,
|
|
195
|
-
mainWorker: `${base}/duckdb-browser-coi.worker.js`,
|
|
196
|
-
pthreadWorker: `${base}/duckdb-browser-coi.pthread.worker.js`
|
|
197
|
-
};
|
|
198
|
-
return bundles;
|
|
199
|
-
}
|
|
200
172
|
async function bootDuckDBWasm(options = {}) {
|
|
201
173
|
const { getJsDelivrBundles, selectBundle, AsyncDuckDB, ConsoleLogger } = await import("@duckdb/duckdb-wasm");
|
|
202
174
|
const bundle = await selectBundle(options.bundles ?? getJsDelivrBundles());
|
|
@@ -271,21 +243,6 @@ async function attachParquetUrlTables(options) {
|
|
|
271
243
|
}
|
|
272
244
|
};
|
|
273
245
|
}
|
|
274
|
-
async function attachSingleTable(options) {
|
|
275
|
-
const { db, conn, table, urls, fetch: fetchImpl = globalThis.fetch.bind(globalThis), schema = "main", fetchInit } = options;
|
|
276
|
-
if (urls.length === 0) return;
|
|
277
|
-
await Promise.all(urls.map(async (url, index) => {
|
|
278
|
-
const response = await fetchImpl(url, fetchInit);
|
|
279
|
-
if (!response.ok) throw new Error(`fetch ${url} failed: ${response.status}`);
|
|
280
|
-
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
281
|
-
await db.registerFileBuffer(fileName(table, index), bytes);
|
|
282
|
-
}));
|
|
283
|
-
const names = urls.map((_, i) => fileName(table, i));
|
|
284
|
-
await conn.query(readParquetViewSql(schema, table, names));
|
|
285
|
-
}
|
|
286
|
-
async function listAttachedTables(conn, schema = "main") {
|
|
287
|
-
return arrowToRows(await conn.query(`SELECT table_name FROM information_schema.tables WHERE table_schema = '${sqlEscape(schema)}'`)).map((r) => String(r.table_name));
|
|
288
|
-
}
|
|
289
246
|
function createBrowserAnalysisRuntime(boot, options = {}) {
|
|
290
247
|
const { db, conn } = boot;
|
|
291
248
|
const schema = options.schema ?? "main";
|
|
@@ -340,7 +297,8 @@ function createBrowserAnalysisRuntime(boot, options = {}) {
|
|
|
340
297
|
} }, {
|
|
341
298
|
schema,
|
|
342
299
|
signal,
|
|
343
|
-
attachedTables
|
|
300
|
+
attachedTables,
|
|
301
|
+
adapter: pgResolverAdapter
|
|
344
302
|
}), params, registry);
|
|
345
303
|
return {
|
|
346
304
|
results: result.results,
|
|
@@ -367,4 +325,4 @@ function createBrowserAnalysisRuntime(boot, options = {}) {
|
|
|
367
325
|
}
|
|
368
326
|
};
|
|
369
327
|
}
|
|
370
|
-
export { DuckDBWasmDatabase, attachParquetTables, attachParquetUrlTables,
|
|
328
|
+
export { DuckDBWasmDatabase, attachParquetTables, attachParquetUrlTables, bootDuckDBWasm, countries, createBrowserAnalysisRuntime, createClient, createInsightRunner, devices, drizzle, keywords, mergeScope, page_keywords, pages, resolveWindow, schema, scopeFor, strikingMomentum };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gscdump/engine-duckdb-wasm",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"description": "DuckDB-WASM engine adapter for @gscdump/analysis — typed browser analytics against parquet via R2.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"drizzle-orm": "^0.45.2",
|
|
48
|
-
"
|
|
49
|
-
"gscdump": "0.
|
|
48
|
+
"gscdump": "0.10.0",
|
|
49
|
+
"@gscdump/engine": "0.10.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@duckdb/duckdb-wasm": "^1.32.0",
|