@gscdump/engine-duckdb-wasm 1.4.11 → 1.5.1

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 CHANGED
@@ -7,5 +7,6 @@ import { overlayViewBody } from "./overlay-view.mjs";
7
7
  import { Schema, countries, dates, hourly_pages, page_queries, pages, queries, schema } from "./schema.mjs";
8
8
  import { InsightRunner, InsightRunnerOptions, ScopedRunnerOptions, TableScope, createInsightRunner, mergeScope, scopeFor } from "./runner.mjs";
9
9
  import { AnalyzeResult, AttachParquetTablesOptions, AttachParquetUrlTablesOptions, AttachedTablesHandle, BootDuckDBWasmOptions, BrowserAnalysisRuntime, BrowserAttachBudgetExceededError, BrowserAttachError, BrowserParquetFile, BrowserParquetTable, BrowserParquetUrlTable, DuckDBWasmBootResult, QueryResult, attachParquetTables, attachParquetUrlTables, attachParquetUrlTablesResult, bootDuckDBWasm, browserAttachErrors, createBrowserAnalysisRuntime, isBrowserAttachError } from "./runtime.mjs";
10
+ import { ObjectAsyncLock, SharedAsyncResource, SharedAsyncResourceOptions, SharedAsyncResourceState, createObjectAsyncLock, createSharedAsyncResource } from "./shared-runtime.mjs";
10
11
  import { ComparisonMode, ResolveWindowOptions, ResolvedWindow, WindowPreset, resolveWindow } from "@gscdump/engine/period";
11
- export { type AnalyzeResult, type AttachOpfsTablesOptions, type AttachParquetTablesOptions, type AttachParquetUrlTablesOptions, type AttachedTablesHandle, type BootDuckDBWasmOptions, type BrowserAnalysisRuntime, BrowserAttachBudgetExceededError, type BrowserAttachError, type BrowserParquetFile, type BrowserParquetTable, type BrowserParquetUrlTable, type ComparisonMode, type CompiledArchetypeSql, type DuckDBWasmBootResult, type DuckDBWasmClient, DuckDBWasmDatabase, type DuckDBWasmDrizzleDatabase, type InsightRunner, type InsightRunnerOptions, type OpfsAttachTiming, type OpfsAttachTimingStage, type OpfsAttachedHandle, type OpfsFileProgress, type OpfsParquetFile, type OpfsParquetTable, OpfsQuotaExceededError, type QueryResult, type ResolveWindowOptions, type ResolvedWindow, type Schema, type ScopedRunnerOptions, type TableScope, type WindowPreset, attachOpfsParquetTables, attachParquetTables, attachParquetUrlTables, attachParquetUrlTablesResult, bootDuckDBWasm, browserAttachErrors, clearOpfsSnapshotCache, compileArchetypeSql, countries, createBrowserAnalysisRuntime, createClient, createInsightRunner, dates, drizzle, estimateOpfsStorage, hourly_pages, isBrowserAttachError, mergeScope, overlayViewBody, page_queries, pages, queries, readOpfsSnapshotFile, requestPersistentStorage, resolveWindow, schema, scopeFor, tableForArchetype };
12
+ export { type AnalyzeResult, type AttachOpfsTablesOptions, type AttachParquetTablesOptions, type AttachParquetUrlTablesOptions, type AttachedTablesHandle, type BootDuckDBWasmOptions, type BrowserAnalysisRuntime, BrowserAttachBudgetExceededError, type BrowserAttachError, type BrowserParquetFile, type BrowserParquetTable, type BrowserParquetUrlTable, type ComparisonMode, type CompiledArchetypeSql, type DuckDBWasmBootResult, type DuckDBWasmClient, DuckDBWasmDatabase, type DuckDBWasmDrizzleDatabase, type InsightRunner, type InsightRunnerOptions, type ObjectAsyncLock, type OpfsAttachTiming, type OpfsAttachTimingStage, type OpfsAttachedHandle, type OpfsFileProgress, type OpfsParquetFile, type OpfsParquetTable, OpfsQuotaExceededError, type QueryResult, type ResolveWindowOptions, type ResolvedWindow, type Schema, type ScopedRunnerOptions, type SharedAsyncResource, type SharedAsyncResourceOptions, type SharedAsyncResourceState, type TableScope, type WindowPreset, attachOpfsParquetTables, attachParquetTables, attachParquetUrlTables, attachParquetUrlTablesResult, bootDuckDBWasm, browserAttachErrors, clearOpfsSnapshotCache, compileArchetypeSql, countries, createBrowserAnalysisRuntime, createClient, createInsightRunner, createObjectAsyncLock, createSharedAsyncResource, dates, drizzle, estimateOpfsStorage, hourly_pages, isBrowserAttachError, mergeScope, overlayViewBody, page_queries, pages, queries, readOpfsSnapshotFile, requestPersistentStorage, resolveWindow, schema, scopeFor, tableForArchetype };
package/dist/index.mjs CHANGED
@@ -7,5 +7,6 @@ import { OpfsQuotaExceededError, attachOpfsParquetTables, clearOpfsSnapshotCache
7
7
  import { countries, dates, hourly_pages, page_queries, pages, queries, schema } from "./schema.mjs";
8
8
  import { createInsightRunner, mergeScope, scopeFor } from "./runner.mjs";
9
9
  import { BrowserAttachBudgetExceededError, attachParquetTables, attachParquetUrlTables, attachParquetUrlTablesResult, bootDuckDBWasm, browserAttachErrors, createBrowserAnalysisRuntime, isBrowserAttachError } from "./runtime.mjs";
10
+ import { createObjectAsyncLock, createSharedAsyncResource } from "./shared-runtime.mjs";
10
11
  import { resolveWindow } from "@gscdump/engine/period";
11
- export { BrowserAttachBudgetExceededError, DuckDBWasmDatabase, OpfsQuotaExceededError, attachOpfsParquetTables, attachParquetTables, attachParquetUrlTables, attachParquetUrlTablesResult, bootDuckDBWasm, browserAttachErrors, clearOpfsSnapshotCache, compileArchetypeSql, countries, createBrowserAnalysisRuntime, createClient, createInsightRunner, dates, drizzle, estimateOpfsStorage, hourly_pages, isBrowserAttachError, mergeScope, overlayViewBody, page_queries, pages, queries, readOpfsSnapshotFile, requestPersistentStorage, resolveWindow, schema, scopeFor, tableForArchetype };
12
+ export { BrowserAttachBudgetExceededError, DuckDBWasmDatabase, OpfsQuotaExceededError, attachOpfsParquetTables, attachParquetTables, attachParquetUrlTables, attachParquetUrlTablesResult, bootDuckDBWasm, browserAttachErrors, clearOpfsSnapshotCache, compileArchetypeSql, countries, createBrowserAnalysisRuntime, createClient, createInsightRunner, createObjectAsyncLock, createSharedAsyncResource, dates, drizzle, estimateOpfsStorage, hourly_pages, isBrowserAttachError, mergeScope, overlayViewBody, page_queries, pages, queries, readOpfsSnapshotFile, requestPersistentStorage, resolveWindow, schema, scopeFor, tableForArchetype };
package/dist/runner.d.mts CHANGED
@@ -15,14 +15,6 @@ interface InsightRunner {
15
15
  close: () => Promise<void>;
16
16
  }
17
17
  declare function createInsightRunner(opts: InsightRunnerOptions): Promise<InsightRunner>;
18
- /**
19
- * Build a per-table predicate set from {siteId, window}. The returned
20
- * `wherePredicates` composes with user-level filters via `mergeScope`.
21
- *
22
- * Note: the current SCHEMAS don't include `site_id` on any table (snapshots
23
- * are already per-site), so `siteId` is a no-op for now — kept in the API
24
- * so consumers can add the predicate without an interface change when
25
- * multi-site snapshots land.
26
- */
27
- declare const scopeFor: (table: "pages" | "queries" | "countries" | "page_queries" | "dates" | "search_appearance" | "search_appearance_pages" | "search_appearance_queries" | "search_appearance_page_queries" | "hourly_pages", opts: ScopedRunnerOptions) => TableScope, mergeScope: typeof import("@gscdump/engine/scope").mergeScope;
18
+ declare const scopeFor: (table: "pages" | "queries" | "countries" | "page_queries" | "dates" | "search_appearance" | "search_appearance_pages" | "search_appearance_queries" | "search_appearance_page_queries" | "hourly_pages", opts: ScopedRunnerOptions) => TableScope;
19
+ declare const mergeScope: typeof import("@gscdump/engine/scope").mergeScope;
28
20
  export { InsightRunner, InsightRunnerOptions, type ScopedRunnerOptions, type TableScope, createInsightRunner, mergeScope, scopeFor };
package/dist/runner.mjs CHANGED
@@ -15,5 +15,7 @@ async function createInsightRunner(opts) {
15
15
  close: () => client.close()
16
16
  };
17
17
  }
18
- const { scopeFor, mergeScope } = createScopedHelpers(schema);
18
+ const scopedHelpers = createScopedHelpers(schema);
19
+ const scopeFor = scopedHelpers.scopeFor;
20
+ const mergeScope = scopedHelpers.mergeScope;
19
21
  export { createInsightRunner, mergeScope, scopeFor };
@@ -0,0 +1,28 @@
1
+ type SharedAsyncResourceState = {
2
+ _tag: 'idle' | 'loading' | 'ready';
3
+ consecutiveFailures: number;
4
+ lastFailureAt: null;
5
+ } | {
6
+ _tag: 'cooldown' | 'exhausted';
7
+ consecutiveFailures: number;
8
+ lastFailureAt: number;
9
+ error: unknown;
10
+ };
11
+ interface SharedAsyncResourceOptions<T> {
12
+ load: () => Promise<T>;
13
+ retryCooldownMs?: number;
14
+ maxConsecutiveFailures?: number;
15
+ now?: () => number;
16
+ onStateChange?: (state: SharedAsyncResourceState) => void;
17
+ }
18
+ interface SharedAsyncResource<T> {
19
+ get: () => Promise<T>;
20
+ state: () => SharedAsyncResourceState;
21
+ reset: () => void;
22
+ }
23
+ declare function createSharedAsyncResource<T>(options: SharedAsyncResourceOptions<T>): SharedAsyncResource<T>;
24
+ interface ObjectAsyncLock<T extends object> {
25
+ run: <R>(key: T, task: () => Promise<R>) => Promise<R>;
26
+ }
27
+ declare function createObjectAsyncLock<T extends object>(onRejected?: (error: unknown) => void): ObjectAsyncLock<T>;
28
+ export { ObjectAsyncLock, SharedAsyncResource, SharedAsyncResourceOptions, SharedAsyncResourceState, createObjectAsyncLock, createSharedAsyncResource };
@@ -0,0 +1,79 @@
1
+ function createSharedAsyncResource(options) {
2
+ const now = options.now ?? Date.now;
3
+ const retryCooldownMs = options.retryCooldownMs ?? 3e4;
4
+ const maxConsecutiveFailures = options.maxConsecutiveFailures ?? 3;
5
+ let promise = null;
6
+ let current = {
7
+ _tag: "idle",
8
+ consecutiveFailures: 0,
9
+ lastFailureAt: null
10
+ };
11
+ const update = (state) => {
12
+ current = state;
13
+ options.onStateChange?.(state);
14
+ };
15
+ const get = () => {
16
+ if (promise) return promise;
17
+ if (current.consecutiveFailures >= maxConsecutiveFailures) {
18
+ if (current._tag !== "cooldown" && current._tag !== "exhausted") return Promise.reject(/* @__PURE__ */ new Error("shared resource exhausted without a recorded failure"));
19
+ update({
20
+ ...current,
21
+ _tag: "exhausted"
22
+ });
23
+ return Promise.reject(current.error);
24
+ }
25
+ if ((current._tag === "cooldown" || current._tag === "exhausted") && now() - current.lastFailureAt < retryCooldownMs) {
26
+ update({
27
+ ...current,
28
+ _tag: "cooldown"
29
+ });
30
+ return Promise.reject(current.error);
31
+ }
32
+ update({
33
+ _tag: "loading",
34
+ consecutiveFailures: current.consecutiveFailures,
35
+ lastFailureAt: null
36
+ });
37
+ promise = options.load().then((resource) => {
38
+ update({
39
+ _tag: "ready",
40
+ consecutiveFailures: 0,
41
+ lastFailureAt: null
42
+ });
43
+ return resource;
44
+ }, (error) => {
45
+ promise = null;
46
+ update({
47
+ _tag: "cooldown",
48
+ consecutiveFailures: current.consecutiveFailures + 1,
49
+ lastFailureAt: now(),
50
+ error
51
+ });
52
+ throw error;
53
+ });
54
+ return promise;
55
+ };
56
+ return {
57
+ get,
58
+ state: () => current,
59
+ reset: () => {
60
+ promise = null;
61
+ update({
62
+ _tag: "idle",
63
+ consecutiveFailures: 0,
64
+ lastFailureAt: null
65
+ });
66
+ }
67
+ };
68
+ }
69
+ function createObjectAsyncLock(onRejected) {
70
+ const chains = /* @__PURE__ */ new WeakMap();
71
+ return { run(key, task) {
72
+ const result = (chains.get(key) ?? Promise.resolve()).then(task);
73
+ chains.set(key, result.then(() => void 0, (error) => {
74
+ onRejected?.(error);
75
+ }));
76
+ return result;
77
+ } };
78
+ }
79
+ export { createObjectAsyncLock, createSharedAsyncResource };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gscdump/engine-duckdb-wasm",
3
3
  "type": "module",
4
- "version": "1.4.11",
4
+ "version": "1.5.1",
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,15 +45,15 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "drizzle-orm": "1.0.0-rc.3",
48
- "@gscdump/contracts": "^1.4.11",
49
- "@gscdump/engine": "^1.4.11",
50
- "gscdump": "^1.4.11"
48
+ "@gscdump/contracts": "^1.5.1",
49
+ "@gscdump/engine": "^1.5.1",
50
+ "gscdump": "^1.5.1"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@duckdb/duckdb-wasm": "1.33.1-dev57.0",
54
54
  "@vitest/browser": "^4.1.10",
55
55
  "@vitest/browser-playwright": "^4.1.10",
56
- "playwright": "^1.61.1",
56
+ "playwright": "^1.62.0",
57
57
  "vitest": "^4.1.10"
58
58
  },
59
59
  "scripts": {