@gscdump/engine-duckdb-wasm 1.5.0 → 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 +2 -1
- package/dist/index.mjs +2 -1
- package/dist/shared-runtime.d.mts +28 -0
- package/dist/shared-runtime.mjs +79 -0
- package/package.json +4 -4
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 };
|
|
@@ -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.5.
|
|
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,9 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"drizzle-orm": "1.0.0-rc.3",
|
|
48
|
-
"@gscdump/contracts": "^1.5.
|
|
49
|
-
"@gscdump/engine": "^1.5.
|
|
50
|
-
"gscdump": "^1.5.
|
|
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",
|