@gscdump/analysis 0.4.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/LICENSE +21 -0
- package/README.md +251 -0
- package/dist/analyzer/index.d.mts +893 -0
- package/dist/analyzer/index.mjs +4944 -0
- package/dist/default-registry.d.mts +93 -0
- package/dist/default-registry.mjs +1957 -0
- package/dist/index.d.mts +620 -0
- package/dist/index.mjs +2873 -0
- package/dist/period/index.d.mts +57 -0
- package/dist/period/index.mjs +150 -0
- package/dist/query/index.d.mts +26 -0
- package/dist/query/index.mjs +340 -0
- package/dist/semantic/index.d.mts +70 -0
- package/dist/semantic/index.mjs +391 -0
- package/dist/source/index.d.mts +427 -0
- package/dist/source/index.mjs +1865 -0
- package/package.json +86 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { BuilderState } from "gscdump/query";
|
|
2
|
+
import { Row } from "@gscdump/engine/contracts";
|
|
3
|
+
import { FileSet } from "@gscdump/engine/resolver";
|
|
4
|
+
import { AnalysisParams } from "gscdump/contracts";
|
|
5
|
+
/**
|
|
6
|
+
* Capabilities a Plan may require of its host. A dispatcher matches these
|
|
7
|
+
* against a source's declared capabilities and rejects mismatches.
|
|
8
|
+
*/
|
|
9
|
+
type Capability = 'executeSql' | 'partitionedParquet' | 'attachedTables' | 'regex' | 'windowTotals' | 'comparisonJoin';
|
|
10
|
+
interface SqlExtraQuery {
|
|
11
|
+
name: string;
|
|
12
|
+
sql: string;
|
|
13
|
+
params: unknown[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* SQL-native plan: SQL string + placeholders, with optional extra file sets
|
|
17
|
+
* and follow-up queries. Mirrors the existing `AnalyzerSpec` shape but
|
|
18
|
+
* renamed for clarity under the unified contract.
|
|
19
|
+
*/
|
|
20
|
+
interface SqlPlan {
|
|
21
|
+
kind: 'sql';
|
|
22
|
+
sql: string;
|
|
23
|
+
params: unknown[];
|
|
24
|
+
current: FileSet;
|
|
25
|
+
previous?: FileSet;
|
|
26
|
+
extraFiles?: Record<string, FileSet>;
|
|
27
|
+
extraQueries?: SqlExtraQuery[];
|
|
28
|
+
/** Emits direct table refs (browser-only). Dispatcher rejects for manifest path. */
|
|
29
|
+
requiresAttachedTables?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface TypedRowQuery<T extends Row = Row> {
|
|
32
|
+
state: BuilderState;
|
|
33
|
+
/** Optional type tag for downstream narrowing. */
|
|
34
|
+
rowType?: (row: Row) => T;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Row-queries plan: a named set of typed `BuilderState` queries. A portable
|
|
38
|
+
* dispatcher runs each against a source's `queryRows` and hands the row
|
|
39
|
+
* collection to `reduce`.
|
|
40
|
+
*/
|
|
41
|
+
interface RowQueriesPlan {
|
|
42
|
+
kind: 'rows';
|
|
43
|
+
queries: Record<string, TypedRowQuery>;
|
|
44
|
+
}
|
|
45
|
+
type Plan = SqlPlan | RowQueriesPlan;
|
|
46
|
+
interface ReduceContext<TRow extends Row = Row> {
|
|
47
|
+
params: AnalysisParams;
|
|
48
|
+
/** Extra SQL-query results keyed by `SqlExtraQuery.name`. */
|
|
49
|
+
extras?: Record<string, TRow[]>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Unified analyzer contract. `TRow` lets authors narrow from the default
|
|
53
|
+
* `Row = Record<string, unknown>` to a typed row shape (e.g. `KeywordRow`)
|
|
54
|
+
* when their reducer assumes specific columns exist — catches drift between
|
|
55
|
+
* `build` (SELECT list) and `reduce` (column access) at compile time.
|
|
56
|
+
*/
|
|
57
|
+
interface Analyzer<P extends AnalysisParams = AnalysisParams, R = unknown, TRow extends Row = Row> {
|
|
58
|
+
/** Stable tool id (e.g. `striking-distance`, `opportunity`). */
|
|
59
|
+
id: string;
|
|
60
|
+
/** Capabilities a host source must provide. */
|
|
61
|
+
requires: readonly Capability[];
|
|
62
|
+
/** Pure: params → plan. Snapshot-testable. */
|
|
63
|
+
build: (params: P) => Plan;
|
|
64
|
+
/** Pure: rows + context → typed result + meta. */
|
|
65
|
+
reduce: (rows: TRow[] | Record<string, TRow[]>, ctx: ReduceContext<TRow>) => {
|
|
66
|
+
results: R;
|
|
67
|
+
meta?: Record<string, unknown>;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
interface AnalyzerVariants {
|
|
71
|
+
sql?: Analyzer;
|
|
72
|
+
rows?: Analyzer;
|
|
73
|
+
}
|
|
74
|
+
interface AnalyzerRegistry {
|
|
75
|
+
listAnalyzerIds: () => readonly string[];
|
|
76
|
+
getAnalyzerVariants: (id: string) => AnalyzerVariants | undefined;
|
|
77
|
+
resolveAnalyzer: (id: string, sourceSupportsSql: boolean) => Analyzer | undefined;
|
|
78
|
+
listAnalyzersFor: (sourceSupportsSql: boolean) => readonly Analyzer[];
|
|
79
|
+
listAnalyzerIdsFor: (source: {
|
|
80
|
+
executeSql?: unknown;
|
|
81
|
+
}) => readonly string[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Default analyzer registry built from every in-tree analyzer: row analyzers
|
|
85
|
+
* plus DuckDB SQL analyzers. Convenience for callers who don't care about
|
|
86
|
+
* bundle size; edge / browser consumers should compose their own narrower
|
|
87
|
+
* registry via `createAnalyzerRegistry`.
|
|
88
|
+
*
|
|
89
|
+
* Importing this module transitively pulls in `@gscdump/engine-duckdb-node`
|
|
90
|
+
* and its DuckDB SQL builder code.
|
|
91
|
+
*/
|
|
92
|
+
declare const defaultAnalyzerRegistry: AnalyzerRegistry;
|
|
93
|
+
export { defaultAnalyzerRegistry };
|