gscdump 1.0.2 → 1.0.3

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.
@@ -1,235 +1,3 @@
1
- import { TableName } from "@gscdump/contracts";
2
- type GscDataState = 'final' | 'all' | 'hourly_all';
3
- type GscAggregationType = 'auto' | 'byPage' | 'byProperty' | 'byNewsShowcasePanel';
4
- interface Ok<A> {
5
- readonly ok: true;
6
- readonly value: A;
7
- }
8
- interface Err<E> {
9
- readonly ok: false;
10
- readonly error: E;
11
- }
12
- type Result<A, E> = Ok<A> | Err<E>;
13
- declare const _default: {
14
- name: string;
15
- 'alpha-2': string;
16
- 'alpha-3': string;
17
- 'country-code': string;
18
- }[];
19
- declare const Devices: {
20
- readonly MOBILE: "MOBILE";
21
- readonly DESKTOP: "DESKTOP";
22
- readonly TABLET: "TABLET";
23
- };
24
- type Device = typeof Devices[keyof typeof Devices];
25
- declare const SearchTypes: {
26
- readonly WEB: "web";
27
- readonly IMAGE: "image";
28
- readonly VIDEO: "video";
29
- readonly NEWS: "news";
30
- readonly DISCOVER: "discover";
31
- readonly GOOGLE_NEWS: "googleNews";
32
- };
33
- type SearchType = typeof SearchTypes[keyof typeof SearchTypes];
34
- declare const Countries: { [K in (typeof _default)[number]["alpha-3"]]: Lowercase<K>; };
35
- type Country = typeof Countries[keyof typeof Countries];
36
- interface DimensionValueMap {
37
- query: string;
38
- queryCanonical: string;
39
- page: string;
40
- country: Country;
41
- device: Device;
42
- searchAppearance: string;
43
- date: string;
44
- /** Hour bucket — ISO-8601 with PT offset, e.g. `2025-07-14T13:00:00-07:00`. Use with `dataState: 'hourly_all'`. */
45
- hour: string;
46
- }
47
- type Dimension = keyof DimensionValueMap;
48
- interface QueryParamValueMap {
49
- searchType: SearchType;
50
- }
51
- type QueryParamName = keyof QueryParamValueMap;
52
- type FilterOperator = 'equals' | 'notEquals' | 'contains' | 'notContains' | 'includingRegex' | 'excludingRegex';
53
- type DateOperator = 'gte' | 'gt' | 'lte' | 'lt' | 'between';
54
- type MetricOperator = 'metricGte' | 'metricGt' | 'metricLte' | 'metricLt' | 'metricBetween';
55
- type SpecialOperator = 'topLevel';
56
- interface InternalFilter {
57
- dimension: Dimension | QueryParamName | Metric;
58
- operator: FilterOperator | DateOperator | MetricOperator | SpecialOperator;
59
- expression: string;
60
- expression2?: string;
61
- }
62
- interface Filter<C = object> {
63
- readonly __filterBrand: 'gscdump.Filter';
64
- readonly _constraints: C;
65
- readonly _filters: InternalFilter[];
66
- readonly _nestedGroups?: Filter<any>[];
67
- readonly _groupType?: 'and' | 'or';
68
- }
69
- type Metric = 'clicks' | 'impressions' | 'ctr' | 'position';
70
- interface BuilderState {
71
- dimensions: Dimension[];
72
- metrics?: Metric[];
73
- filter?: Filter<any>;
74
- prefilter?: Filter<any>;
75
- orderBy?: {
76
- column: Metric | 'date';
77
- dir: 'asc' | 'desc';
78
- };
79
- rowLimit?: number;
80
- startRow?: number;
81
- /** GSC `dataState`. `'hourly_all'` is required when grouping by `hour`. */
82
- dataState?: GscDataState;
83
- /** GSC `aggregationType`. `'byNewsShowcasePanel'` requires `type=discover|googleNews` with NEWS_SHOWCASE searchAppearance. */
84
- aggregationType?: GscAggregationType;
85
- /** GSC search corpus. Wins over any `searchType` filter when both are set. */
86
- searchType?: SearchType;
87
- }
88
- type QueryErrorKind = 'missing-date-range' | 'invalid-row-limit' | 'invalid-start-row' | 'invalid-data-state' | 'invalid-aggregation-type' | 'invalid-builder-state' | 'invalid-filter' | 'unsupported-capability' | 'unresolvable-dataset';
89
- type QueryError = {
90
- kind: 'missing-date-range';
91
- message: string;
92
- } | {
93
- kind: 'invalid-row-limit';
94
- value: unknown;
95
- message: string;
96
- } | {
97
- kind: 'invalid-start-row';
98
- value: unknown;
99
- message: string;
100
- } | {
101
- kind: 'invalid-data-state';
102
- message: string;
103
- } | {
104
- kind: 'invalid-aggregation-type';
105
- message: string;
106
- } | {
107
- kind: 'invalid-builder-state';
108
- message: string;
109
- cause?: unknown;
110
- } | {
111
- kind: 'invalid-filter';
112
- message: string;
113
- } | {
114
- kind: 'unsupported-capability';
115
- capability: string;
116
- context: string;
117
- message: string;
118
- } | {
119
- kind: 'unresolvable-dataset';
120
- dimensions: readonly Dimension[];
121
- filterDims: readonly Dimension[];
122
- message: string;
123
- };
124
- /**
125
- * Thrown when a query needs a planner capability (regex pushdown, comparison
126
- * joins, multi-dataset reads) the target engine lacks. Engines catch it to fall
127
- * back to the live GSC API. Carries the typed `queryError` value so a caller can
128
- * read the modelled failure instead of parsing the message.
129
- */
130
- declare class UnsupportedLogicalCapabilityError extends Error {
131
- readonly queryError: Extract<QueryError, {
132
- kind: 'unsupported-capability';
133
- }>;
134
- constructor(capability: string, context: string);
135
- }
136
- /**
137
- * Thrown when a query's grouped + filtered dimensions span more than one stored
138
- * dataset. Replaces the resolver's raw "unknown column" error so hosts can map
139
- * it to a 4xx instead of leaking an opaque 500. Carries the typed `queryError`.
140
- */
141
- declare class UnresolvableDatasetError extends Error {
142
- readonly queryError: Extract<QueryError, {
143
- kind: 'unresolvable-dataset';
144
- }>;
145
- constructor(dimensions: readonly Dimension[], filterDims?: readonly Dimension[]);
146
- }
147
- type LogicalDataset = TableName;
148
- type ComparisonFilter = 'new' | 'lost' | 'improving' | 'declining';
149
- interface PlannerCapabilities {
150
- regex?: boolean;
151
- multiDataset?: boolean;
152
- comparisonJoin?: boolean;
153
- windowTotals?: boolean;
154
- }
155
- interface LogicalDimensionFilter {
156
- dimension: Dimension;
157
- operator: FilterOperator;
158
- expression: string;
159
- expression2?: string;
160
- }
161
- interface LogicalMetricFilter {
162
- metric: Metric;
163
- operator: MetricOperator;
164
- expression: number;
165
- expression2?: number;
166
- }
167
- interface LogicalFilterLeaf {
168
- kind: 'leaf';
169
- filter: LogicalDimensionFilter;
170
- }
171
- interface LogicalFilterGroup {
172
- kind: 'group';
173
- groupType: 'and' | 'or';
174
- children: LogicalFilterNode[];
175
- }
176
- type LogicalFilterNode = LogicalFilterLeaf | LogicalFilterGroup;
177
- interface LogicalQueryPlan {
178
- dataset: LogicalDataset;
179
- dimensions: Dimension[];
180
- groupByDimensions: Dimension[];
181
- hasDate: boolean;
182
- metrics: Metric[];
183
- dateRange: {
184
- startDate: string;
185
- endDate: string;
186
- };
187
- dimensionFilters: LogicalDimensionFilter[];
188
- dimensionFilterTree?: LogicalFilterNode;
189
- metricFilters: LogicalMetricFilter[];
190
- prefilters: LogicalMetricFilter[];
191
- specialFilters: {
192
- topLevel: boolean;
193
- };
194
- queryParams: Partial<Record<QueryParamName, string>>;
195
- orderBy?: BuilderState['orderBy'];
196
- rowLimit?: number;
197
- startRow?: number;
198
- }
199
- interface LogicalComparisonPlan {
200
- current: LogicalQueryPlan;
201
- previous: LogicalQueryPlan;
202
- comparisonFilter?: ComparisonFilter;
203
- }
204
- declare function inferDataset(dimensions: readonly Dimension[], filterDims?: readonly Dimension[]): LogicalDataset;
205
- /**
206
- * True when every grouped + filtered dimension fits inside one stored dataset,
207
- * i.e. the query is answerable from stored Parquet/D1 tables without a live
208
- * GSC call. `inferDataset` always returns *some* dataset; this predicate is
209
- * how callers tell a genuine match from one that will fail at column-resolve
210
- * time.
211
- */
212
- declare function isDatasetResolvable(dimensions: readonly Dimension[], filterDims?: readonly Dimension[]): boolean;
213
- /**
214
- * `BuilderState`-level convenience for {@link isDatasetResolvable}: extracts
215
- * the state's dimension filters (the same way `buildLogicalPlan` does) and
216
- * checks them against the grouped dimensions. Lets routing code (e.g. the
217
- * composite source) detect a cross-dimension query without rebuilding a plan.
218
- */
219
- declare function isStateResolvable(state: BuilderState): boolean;
220
- /**
221
- * Errors-as-values core: builds the logical plan or returns a typed `QueryError`
222
- * for every modelled failure (missing date range, a regex filter on an engine
223
- * without regex pushdown, a cross-dimension query with no stored home).
224
- * `buildLogicalPlan` is the throwing wrapper for call sites that prefer exceptions.
225
- */
226
- declare function buildLogicalPlanResult(state: BuilderState, capabilities?: PlannerCapabilities): Result<LogicalQueryPlan, QueryError>;
227
- declare function buildLogicalPlan(state: BuilderState, capabilities?: PlannerCapabilities): LogicalQueryPlan;
228
- /**
229
- * Errors-as-values core for the comparison plan: returns a typed `QueryError`
230
- * when the engine lacks the comparison-join or multi-dataset capability the
231
- * paired queries need, or when either side fails to plan.
232
- */
233
- declare function buildLogicalComparisonPlanResult(current: BuilderState, previous: BuilderState, capabilities?: PlannerCapabilities, comparisonFilter?: ComparisonFilter): Result<LogicalComparisonPlan, QueryError>;
234
- declare function buildLogicalComparisonPlan(current: BuilderState, previous: BuilderState, capabilities?: PlannerCapabilities, comparisonFilter?: ComparisonFilter): LogicalComparisonPlan;
1
+ import { TableName } from "../_chunks/contracts.mjs";
2
+ import { ComparisonFilter, LogicalComparisonPlan, LogicalDataset, LogicalDimensionFilter, LogicalFilterGroup, LogicalFilterLeaf, LogicalFilterNode, LogicalMetricFilter, LogicalQueryPlan, PlannerCapabilities, QueryError, QueryErrorKind, UnresolvableDatasetError, UnsupportedLogicalCapabilityError, buildLogicalComparisonPlan, buildLogicalComparisonPlanResult, buildLogicalPlan, buildLogicalPlanResult, inferDataset, isDatasetResolvable, isStateResolvable } from "../_chunks/plan.mjs";
235
3
  export { ComparisonFilter, LogicalComparisonPlan, LogicalDataset, LogicalDimensionFilter, LogicalFilterGroup, LogicalFilterLeaf, LogicalFilterNode, LogicalMetricFilter, LogicalQueryPlan, PlannerCapabilities, type QueryError, type QueryErrorKind, type TableName, UnresolvableDatasetError, UnsupportedLogicalCapabilityError, buildLogicalComparisonPlan, buildLogicalComparisonPlanResult, buildLogicalPlan, buildLogicalPlanResult, inferDataset, isDatasetResolvable, isStateResolvable };