gscdump 1.4.0 → 1.4.2

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.
Files changed (71) hide show
  1. package/dist/api/batch.d.mts +12 -0
  2. package/dist/api/batch.mjs +29 -0
  3. package/dist/api/indexing.d.mts +37 -0
  4. package/dist/api/indexing.mjs +25 -0
  5. package/dist/api/inspection.d.mts +89 -0
  6. package/dist/api/inspection.mjs +128 -0
  7. package/dist/api/oauth.d.mts +48 -0
  8. package/dist/api/oauth.mjs +154 -0
  9. package/dist/api/sites.d.mts +45 -0
  10. package/dist/api/sites.mjs +34 -0
  11. package/dist/api/verification.d.mts +43 -0
  12. package/dist/api/verification.mjs +89 -0
  13. package/dist/contracts.d.mts +46 -1
  14. package/dist/core/cli-format.mjs +9 -0
  15. package/dist/core/client.d.mts +122 -0
  16. package/dist/core/client.mjs +246 -0
  17. package/dist/core/errors.d.mts +66 -0
  18. package/dist/core/errors.mjs +207 -0
  19. package/dist/core/indexing-issues.d.mts +60 -0
  20. package/dist/core/indexing-issues.mjs +139 -0
  21. package/dist/core/property.d.mts +41 -0
  22. package/dist/core/property.mjs +74 -0
  23. package/dist/core/quota.d.mts +2 -0
  24. package/dist/core/quota.mjs +2 -0
  25. package/dist/core/result.d.mts +19 -1
  26. package/dist/core/scope-values.d.mts +7 -0
  27. package/dist/core/scope-values.mjs +15 -0
  28. package/dist/core/scopes.d.mts +5 -0
  29. package/dist/core/scopes.mjs +11 -0
  30. package/dist/core/site-url.d.mts +25 -0
  31. package/dist/core/site-url.mjs +30 -0
  32. package/dist/core/types.d.mts +201 -0
  33. package/dist/core/types.mjs +1 -0
  34. package/dist/dates.d.mts +2 -2
  35. package/dist/dates.mjs +2 -2
  36. package/dist/index.d.mts +20 -814
  37. package/dist/index.mjs +19 -1243
  38. package/dist/onboarding.d.mts +2 -0
  39. package/dist/onboarding.mjs +2 -0
  40. package/dist/{_chunks → query}/builder.d.mts +2 -2
  41. package/dist/query/builder.mjs +86 -0
  42. package/dist/query/columns.d.mts +15 -0
  43. package/dist/query/columns.mjs +23 -0
  44. package/dist/query/constants.d.mts +19 -0
  45. package/dist/query/constants.mjs +16 -0
  46. package/dist/query/errors.d.mts +85 -0
  47. package/dist/query/errors.mjs +141 -0
  48. package/dist/query/index.d.mts +9 -75
  49. package/dist/query/index.mjs +7 -230
  50. package/dist/query/operator-meta.mjs +41 -0
  51. package/dist/query/operators.d.mts +24 -0
  52. package/dist/query/operators.mjs +124 -0
  53. package/dist/query/plan.d.mts +92 -2
  54. package/dist/query/plan.mjs +3 -1
  55. package/dist/query/resolver.d.mts +40 -0
  56. package/dist/query/resolver.mjs +243 -0
  57. package/dist/{_chunks → query}/types.d.mts +3 -25
  58. package/dist/query/utils/countries.d.mts +7 -0
  59. package/dist/{_chunks/resolver.mjs → query/utils/countries.mjs} +1 -434
  60. package/dist/{_chunks → query/utils}/dayjs.mjs +1 -1
  61. package/dist/sitemap.d.mts +26 -0
  62. package/dist/sitemap.mjs +70 -0
  63. package/dist/url.d.mts +9 -0
  64. package/dist/url.mjs +6 -0
  65. package/package.json +2 -2
  66. package/dist/_chunks/contracts.d.mts +0 -47
  67. package/dist/_chunks/plan.d.mts +0 -175
  68. package/dist/_chunks/result.d.mts +0 -20
  69. /package/dist/{_chunks → core}/gsc-dates.d.mts +0 -0
  70. /package/dist/{_chunks → core}/gsc-dates.mjs +0 -0
  71. /package/dist/{_chunks → query/utils}/dayjs.d.mts +0 -0
@@ -0,0 +1,2 @@
1
+ import { AccountNextAction, AccountStatus, AnalyticsNextAction, AnalyticsStatus, GSCDUMP_ONBOARDING_CONTRACT_VERSION, GSCDUMP_OPTIONAL_INDEXING_SCOPE, GSCDUMP_REQUIRED_ANALYTICS_SCOPE, GSCDUMP_WRITE_ANALYTICS_SCOPE, IndexingNextAction, IndexingStatus, LifecycleError, LifecycleErrorCode, LifecycleProgress, LifecycleWebhookEnvelope, LifecycleWebhookEvent, PartnerLifecycleAccount, PartnerLifecycleResponse, PartnerLifecycleSite, PropertyNextAction, PropertyStatus, QuerySourceMode, SitemapNextAction, SitemapStatus, accountNextActions, accountStatuses, analyticsNextActions, analyticsStatuses, hasOptionalIndexingScope, hasRequiredAnalyticsScope, indexingNextActions, indexingStatuses, lifecycleErrorCodes, parseGrantedScopes, propertyNextActions, propertyStatuses, querySourceModes, sitemapNextActions, sitemapStatuses } from "@gscdump/contracts/partner";
2
+ export { type AccountNextAction, type AccountStatus, type AnalyticsNextAction, type AnalyticsStatus, GSCDUMP_ONBOARDING_CONTRACT_VERSION, GSCDUMP_OPTIONAL_INDEXING_SCOPE, GSCDUMP_REQUIRED_ANALYTICS_SCOPE, GSCDUMP_WRITE_ANALYTICS_SCOPE, type IndexingNextAction, type IndexingStatus, type LifecycleError, type LifecycleErrorCode, type LifecycleProgress, type LifecycleWebhookEnvelope, type LifecycleWebhookEvent, type PartnerLifecycleAccount, type PartnerLifecycleResponse, type PartnerLifecycleSite, type PropertyNextAction, type PropertyStatus, type QuerySourceMode, type SitemapNextAction, type SitemapStatus, accountNextActions, accountStatuses, analyticsNextActions, analyticsStatuses, hasOptionalIndexingScope, hasRequiredAnalyticsScope, indexingNextActions, indexingStatuses, lifecycleErrorCodes, parseGrantedScopes, propertyNextActions, propertyStatuses, querySourceModes, sitemapNextActions, sitemapStatuses };
@@ -0,0 +1,2 @@
1
+ import { GSCDUMP_ONBOARDING_CONTRACT_VERSION, GSCDUMP_OPTIONAL_INDEXING_SCOPE, GSCDUMP_REQUIRED_ANALYTICS_SCOPE, GSCDUMP_WRITE_ANALYTICS_SCOPE, accountNextActions, accountStatuses, analyticsNextActions, analyticsStatuses, hasOptionalIndexingScope, hasRequiredAnalyticsScope, indexingNextActions, indexingStatuses, lifecycleErrorCodes, parseGrantedScopes, propertyNextActions, propertyStatuses, querySourceModes, sitemapNextActions, sitemapStatuses } from "@gscdump/contracts/partner";
2
+ export { GSCDUMP_ONBOARDING_CONTRACT_VERSION, GSCDUMP_OPTIONAL_INDEXING_SCOPE, GSCDUMP_REQUIRED_ANALYTICS_SCOPE, GSCDUMP_WRITE_ANALYTICS_SCOPE, accountNextActions, accountStatuses, analyticsNextActions, analyticsStatuses, hasOptionalIndexingScope, hasRequiredAnalyticsScope, indexingNextActions, indexingStatuses, lifecycleErrorCodes, parseGrantedScopes, propertyNextActions, propertyStatuses, querySourceModes, sitemapNextActions, sitemapStatuses };
@@ -1,4 +1,4 @@
1
- import { GscAggregationType, GscDataState, GscSearchAnalyticsRequest, GscSearchType } from "./contracts.mjs";
1
+ import { GscAggregationType, GscDataState, GscSearchAnalyticsRequest, GscSearchType } from "../contracts.mjs";
2
2
  import { BuilderState, Column, Dimension, Filter, Metric, MetricColumn } from "./types.mjs";
3
3
  type SelectableColumn = Column<Dimension> | MetricColumn<Metric>;
4
4
  type OrderableColumn = MetricColumn<Metric> | Column<'date'>;
@@ -21,4 +21,4 @@ interface GSCQueryBuilder<D extends Dimension[] = [], C = object> {
21
21
  getState: () => BuilderState;
22
22
  }
23
23
  declare const gsc: GSCQueryBuilder<[], object>;
24
- export { GSCQueryBuilder, gsc };
24
+ export { GSCQueryBuilder, OrderableColumn, SelectableColumn, gsc };
@@ -0,0 +1,86 @@
1
+ import { resolveToBody } from "./resolver.mjs";
2
+ function isDimensionString(v) {
3
+ return typeof v === "string";
4
+ }
5
+ function isMetricColumn(v) {
6
+ return typeof v === "object" && v !== null && "metric" in v;
7
+ }
8
+ function isDimensionColumn(v) {
9
+ return typeof v === "object" && v !== null && "dimension" in v && !("metric" in v);
10
+ }
11
+ function createBuilder(state) {
12
+ return {
13
+ select(...args) {
14
+ const dimensions = [];
15
+ const metrics = [];
16
+ for (const arg of args) if (isDimensionString(arg)) dimensions.push(arg);
17
+ else if (isDimensionColumn(arg)) dimensions.push(arg.dimension);
18
+ else if (isMetricColumn(arg)) metrics.push(arg.metric);
19
+ return createBuilder({
20
+ ...state,
21
+ dimensions,
22
+ metrics: metrics.length > 0 ? metrics : void 0
23
+ });
24
+ },
25
+ where(filter) {
26
+ return createBuilder({
27
+ ...state,
28
+ filter
29
+ });
30
+ },
31
+ prefilter(filter) {
32
+ return createBuilder({
33
+ ...state,
34
+ prefilter: filter
35
+ });
36
+ },
37
+ orderBy(col, dir) {
38
+ const column = isMetricColumn(col) ? col.metric : col.dimension;
39
+ return createBuilder({
40
+ ...state,
41
+ orderBy: {
42
+ column,
43
+ dir
44
+ }
45
+ });
46
+ },
47
+ limit(n) {
48
+ return createBuilder({
49
+ ...state,
50
+ rowLimit: n
51
+ });
52
+ },
53
+ offset(n) {
54
+ return createBuilder({
55
+ ...state,
56
+ startRow: n
57
+ });
58
+ },
59
+ dataState(s) {
60
+ return createBuilder({
61
+ ...state,
62
+ dataState: s
63
+ });
64
+ },
65
+ aggregationType(t) {
66
+ return createBuilder({
67
+ ...state,
68
+ aggregationType: t
69
+ });
70
+ },
71
+ type(t) {
72
+ return createBuilder({
73
+ ...state,
74
+ searchType: t
75
+ });
76
+ },
77
+ toBody() {
78
+ return resolveToBody(state);
79
+ },
80
+ getState() {
81
+ return { ...state };
82
+ }
83
+ };
84
+ }
85
+ const gsc = createBuilder({ dimensions: [] });
86
+ export { gsc };
@@ -0,0 +1,15 @@
1
+ import { Column, MetricColumn, QueryParam } from "./types.mjs";
2
+ declare const page: Column<"page">;
3
+ declare const query: Column<"query">;
4
+ declare const queryCanonical: Column<"queryCanonical">;
5
+ declare const device: Column<"device">;
6
+ declare const country: Column<"country">;
7
+ declare const searchAppearance: Column<"searchAppearance">;
8
+ declare const date: Column<"date">;
9
+ declare const hour: Column<"hour">;
10
+ declare const clicks: MetricColumn<"clicks">;
11
+ declare const impressions: MetricColumn<"impressions">;
12
+ declare const ctr: MetricColumn<"ctr">;
13
+ declare const position: MetricColumn<"position">;
14
+ declare const searchType: QueryParam<"searchType">;
15
+ export { clicks, country, ctr, date, device, hour, impressions, page, position, query, queryCanonical, searchAppearance, searchType };
@@ -0,0 +1,23 @@
1
+ function createColumn(dimension) {
2
+ return { dimension };
3
+ }
4
+ function createMetricColumn(metric) {
5
+ return { metric };
6
+ }
7
+ function createQueryParam(param) {
8
+ return { param };
9
+ }
10
+ const page = createColumn("page");
11
+ const query = createColumn("query");
12
+ const queryCanonical = createColumn("queryCanonical");
13
+ const device = createColumn("device");
14
+ const country = createColumn("country");
15
+ const searchAppearance = createColumn("searchAppearance");
16
+ const date = createColumn("date");
17
+ const hour = createColumn("hour");
18
+ const clicks = createMetricColumn("clicks");
19
+ const impressions = createMetricColumn("impressions");
20
+ const ctr = createMetricColumn("ctr");
21
+ const position = createMetricColumn("position");
22
+ const searchType = createQueryParam("searchType");
23
+ export { clicks, country, ctr, date, device, hour, impressions, page, position, query, queryCanonical, searchAppearance, searchType };
@@ -0,0 +1,19 @@
1
+ import _default from "./utils/countries.mjs";
2
+ declare const Devices: {
3
+ readonly MOBILE: 'MOBILE';
4
+ readonly DESKTOP: 'DESKTOP';
5
+ readonly TABLET: 'TABLET';
6
+ };
7
+ type Device = typeof Devices[keyof typeof Devices];
8
+ declare const SearchTypes: {
9
+ readonly WEB: 'web';
10
+ readonly IMAGE: 'image';
11
+ readonly VIDEO: 'video';
12
+ readonly NEWS: 'news';
13
+ readonly DISCOVER: 'discover';
14
+ readonly GOOGLE_NEWS: 'googleNews';
15
+ };
16
+ type SearchType = typeof SearchTypes[keyof typeof SearchTypes];
17
+ declare const Countries: { [K in typeof _default[number]['alpha-3']]: Lowercase<K>; };
18
+ type Country = typeof Countries[keyof typeof Countries];
19
+ export { Countries, Country, Device, Devices, SearchType, SearchTypes };
@@ -0,0 +1,16 @@
1
+ import countries_default from "./utils/countries.mjs";
2
+ const Devices = {
3
+ MOBILE: "MOBILE",
4
+ DESKTOP: "DESKTOP",
5
+ TABLET: "TABLET"
6
+ };
7
+ const SearchTypes = {
8
+ WEB: "web",
9
+ IMAGE: "image",
10
+ VIDEO: "video",
11
+ NEWS: "news",
12
+ DISCOVER: "discover",
13
+ GOOGLE_NEWS: "googleNews"
14
+ };
15
+ const Countries = Object.fromEntries(countries_default.map((c) => [c["alpha-3"], c["alpha-3"].toLowerCase()]));
16
+ export { Countries, Devices, SearchTypes };
@@ -0,0 +1,85 @@
1
+ import { Dimension } from "./types.mjs";
2
+ 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';
3
+ type QueryError = {
4
+ kind: 'missing-date-range';
5
+ message: string;
6
+ } | {
7
+ kind: 'invalid-row-limit';
8
+ value: unknown;
9
+ message: string;
10
+ } | {
11
+ kind: 'invalid-start-row';
12
+ value: unknown;
13
+ message: string;
14
+ } | {
15
+ kind: 'invalid-data-state';
16
+ message: string;
17
+ } | {
18
+ kind: 'invalid-aggregation-type';
19
+ message: string;
20
+ } | {
21
+ kind: 'invalid-builder-state';
22
+ message: string;
23
+ cause?: unknown;
24
+ } | {
25
+ kind: 'invalid-filter';
26
+ message: string;
27
+ } | {
28
+ kind: 'unsupported-capability';
29
+ capability: string;
30
+ context: string;
31
+ message: string;
32
+ } | {
33
+ kind: 'unresolvable-dataset';
34
+ dimensions: readonly Dimension[];
35
+ filterDims: readonly Dimension[];
36
+ message: string;
37
+ };
38
+ declare const queryErrors: {
39
+ readonly missingDateRange: () => QueryError;
40
+ readonly invalidRowLimit: (value: unknown) => QueryError;
41
+ readonly invalidStartRow: (value: unknown) => QueryError;
42
+ readonly hourDimensionRequiresHourlyState: () => QueryError;
43
+ readonly hourlyStateRequiresHourDimension: () => QueryError;
44
+ readonly byPropertyUnsupportedSearchType: () => QueryError;
45
+ readonly byPropertyNotAllowedWithPage: () => QueryError;
46
+ readonly byNewsShowcaseRequiresSearchType: () => QueryError;
47
+ readonly byNewsShowcaseNotAllowedWithPage: () => QueryError;
48
+ readonly byNewsShowcaseRequiresShowcaseFilter: () => QueryError;
49
+ readonly invalidBuilderState: (cause?: unknown) => QueryError;
50
+ readonly malformedFilterLeaf: () => QueryError;
51
+ readonly unsupportedCapability: (capability: string, context: string) => QueryError;
52
+ readonly unresolvableDataset: (dimensions: readonly Dimension[], filterDims?: readonly Dimension[]) => QueryError;
53
+ };
54
+ declare function isQueryError(value: unknown): value is QueryError;
55
+ /**
56
+ * Thrown when a query needs a planner capability (regex pushdown, comparison
57
+ * joins, multi-dataset reads) the target engine lacks. Engines catch it to fall
58
+ * back to the live GSC API. Carries the typed `queryError` value so a caller can
59
+ * read the modelled failure instead of parsing the message.
60
+ */
61
+ declare class UnsupportedLogicalCapabilityError extends Error {
62
+ readonly queryError: Extract<QueryError, {
63
+ kind: 'unsupported-capability';
64
+ }>;
65
+ constructor(capability: string, context: string);
66
+ }
67
+ /**
68
+ * Thrown when a query's grouped + filtered dimensions span more than one stored
69
+ * dataset. Replaces the resolver's raw "unknown column" error so hosts can map
70
+ * it to a 4xx instead of leaking an opaque 500. Carries the typed `queryError`.
71
+ */
72
+ declare class UnresolvableDatasetError extends Error {
73
+ readonly queryError: Extract<QueryError, {
74
+ kind: 'unresolvable-dataset';
75
+ }>;
76
+ constructor(dimensions: readonly Dimension[], filterDims?: readonly Dimension[]);
77
+ }
78
+ /**
79
+ * Re-raises a `QueryError` value as an `Error`, preserving the historical class
80
+ * identity for the two errors engines match on by name (`UnresolvableDatasetError`,
81
+ * `UnsupportedLogicalCapabilityError`). Pairs with `unwrapResult` so a
82
+ * `fooResult(): Result<A, QueryError>` core can back a throwing `foo()`.
83
+ */
84
+ declare function queryErrorToException(error: QueryError): Error;
85
+ export { QueryError, QueryErrorKind, UnresolvableDatasetError, UnsupportedLogicalCapabilityError, isQueryError, queryErrorToException, queryErrors };
@@ -0,0 +1,141 @@
1
+ const TIME_AXIS_DIMENSIONS = /* @__PURE__ */ new Set(["date", "hour"]);
2
+ const queryErrors = {
3
+ missingDateRange() {
4
+ return {
5
+ kind: "missing-date-range",
6
+ message: "Date range required: use .where(between(date, start, end)) or .where(and(gte(date, start), lte(date, end)))"
7
+ };
8
+ },
9
+ invalidRowLimit(value) {
10
+ return {
11
+ kind: "invalid-row-limit",
12
+ value,
13
+ message: `rowLimit must be a positive integer, got ${value}`
14
+ };
15
+ },
16
+ invalidStartRow(value) {
17
+ return {
18
+ kind: "invalid-start-row",
19
+ value,
20
+ message: `startRow must be a non-negative integer, got ${value}`
21
+ };
22
+ },
23
+ hourDimensionRequiresHourlyState() {
24
+ return {
25
+ kind: "invalid-data-state",
26
+ message: "hour dimension requires dataState: \"hourly_all\""
27
+ };
28
+ },
29
+ hourlyStateRequiresHourDimension() {
30
+ return {
31
+ kind: "invalid-data-state",
32
+ message: "dataState: \"hourly_all\" requires grouping by hour dimension"
33
+ };
34
+ },
35
+ byPropertyUnsupportedSearchType() {
36
+ return {
37
+ kind: "invalid-aggregation-type",
38
+ message: "aggregationType: \"byProperty\" is not supported for type \"discover\" or \"googleNews\""
39
+ };
40
+ },
41
+ byPropertyNotAllowedWithPage() {
42
+ return {
43
+ kind: "invalid-aggregation-type",
44
+ message: "aggregationType: \"byProperty\" is not allowed when grouping or filtering by page"
45
+ };
46
+ },
47
+ byNewsShowcaseRequiresSearchType() {
48
+ return {
49
+ kind: "invalid-aggregation-type",
50
+ message: "aggregationType: \"byNewsShowcasePanel\" requires type \"discover\" or \"googleNews\""
51
+ };
52
+ },
53
+ byNewsShowcaseNotAllowedWithPage() {
54
+ return {
55
+ kind: "invalid-aggregation-type",
56
+ message: "aggregationType: \"byNewsShowcasePanel\" is not allowed when grouping or filtering by page"
57
+ };
58
+ },
59
+ byNewsShowcaseRequiresShowcaseFilter() {
60
+ return {
61
+ kind: "invalid-aggregation-type",
62
+ message: "aggregationType: \"byNewsShowcasePanel\" requires a searchAppearance equals \"NEWS_SHOWCASE\" filter and no other searchAppearance filter"
63
+ };
64
+ },
65
+ invalidBuilderState(cause) {
66
+ return {
67
+ kind: "invalid-builder-state",
68
+ cause,
69
+ message: "Invalid state"
70
+ };
71
+ },
72
+ malformedFilterLeaf() {
73
+ return {
74
+ kind: "invalid-filter",
75
+ message: "Malformed filter: each filter leaf requires a string `dimension` and `operator`"
76
+ };
77
+ },
78
+ unsupportedCapability(capability, context) {
79
+ return {
80
+ kind: "unsupported-capability",
81
+ capability,
82
+ context,
83
+ message: `${context} requires ${capability} capability`
84
+ };
85
+ },
86
+ unresolvableDataset(dimensions, filterDims = []) {
87
+ const grouped = dimensions.filter((d) => !TIME_AXIS_DIMENSIONS.has(d));
88
+ const filtered = filterDims.filter((d) => !TIME_AXIS_DIMENSIONS.has(d));
89
+ return {
90
+ kind: "unresolvable-dataset",
91
+ dimensions,
92
+ filterDims,
93
+ message: `Cannot resolve a [${grouped.join(", ")}] breakdown filtered by [${filtered.join(", ")}] from stored data: these dimensions live in separate per-dimension tables. Only the live GSC API computes cross-dimension aggregates.`
94
+ };
95
+ }
96
+ };
97
+ const QUERY_ERROR_KINDS = /* @__PURE__ */ new Set([
98
+ "missing-date-range",
99
+ "invalid-row-limit",
100
+ "invalid-start-row",
101
+ "invalid-data-state",
102
+ "invalid-aggregation-type",
103
+ "invalid-builder-state",
104
+ "invalid-filter",
105
+ "unsupported-capability",
106
+ "unresolvable-dataset"
107
+ ]);
108
+ function isQueryError(value) {
109
+ return typeof value === "object" && value !== null && QUERY_ERROR_KINDS.has(value.kind) && typeof value.message === "string";
110
+ }
111
+ var UnsupportedLogicalCapabilityError = class extends Error {
112
+ queryError;
113
+ constructor(capability, context) {
114
+ const error = queryErrors.unsupportedCapability(capability, context);
115
+ super(error.message);
116
+ this.name = "UnsupportedLogicalCapabilityError";
117
+ this.queryError = error;
118
+ }
119
+ };
120
+ var UnresolvableDatasetError = class extends Error {
121
+ queryError;
122
+ constructor(dimensions, filterDims = []) {
123
+ const error = queryErrors.unresolvableDataset(dimensions, filterDims);
124
+ super(error.message);
125
+ this.name = "UnresolvableDatasetError";
126
+ this.queryError = error;
127
+ }
128
+ };
129
+ function queryErrorToException(error) {
130
+ switch (error.kind) {
131
+ case "unsupported-capability": return new UnsupportedLogicalCapabilityError(error.capability, error.context);
132
+ case "unresolvable-dataset": return new UnresolvableDatasetError(error.dimensions, error.filterDims);
133
+ default: {
134
+ const exception = new Error(error.message);
135
+ if ("cause" in error && error.cause !== void 0) exception.cause = error.cause;
136
+ exception.queryError = error;
137
+ return exception;
138
+ }
139
+ }
140
+ }
141
+ export { UnresolvableDatasetError, UnsupportedLogicalCapabilityError, isQueryError, queryErrorToException, queryErrors };
@@ -1,78 +1,12 @@
1
- import { GscSearchAnalyticsRequest } from "../_chunks/contracts.mjs";
2
- import { Result } from "../_chunks/result.mjs";
3
- import { currentPstDate } from "../_chunks/dayjs.mjs";
4
- import { BuilderState, Column, Countries, Country, Device, Devices, Dimension, DimensionValueMap, Filter, FilterInput, GSCResult, GSCRow, InternalFilter, JsonFilter, JsonInternalFilter, MergeConstraints, Metric, MetricColumn, QueryParam, QueryParamName, QueryParamValueMap, SearchType, SearchTypes } from "../_chunks/types.mjs";
5
- import { GSCQueryBuilder, gsc } from "../_chunks/builder.mjs";
6
- import { ComparisonFilter, LogicalComparisonPlan, LogicalDataset, LogicalDimensionFilter, LogicalMetricFilter, LogicalQueryPlan, PlannerCapabilities, QueryError, QueryErrorKind, UnresolvableDatasetError, UnsupportedLogicalCapabilityError, buildLogicalComparisonPlan, buildLogicalComparisonPlanResult, buildLogicalPlan, buildLogicalPlanResult, isQueryError, queryErrorToException, queryErrors } from "../_chunks/plan.mjs";
7
- declare const page: Column<"page">;
8
- declare const query: Column<"query">;
9
- declare const queryCanonical: Column<"queryCanonical">;
10
- declare const device: Column<"device">;
11
- declare const country: Column<"country">;
12
- declare const searchAppearance: Column<"searchAppearance">;
13
- declare const date: Column<"date">;
14
- declare const hour: Column<"hour">;
15
- declare const clicks: MetricColumn<"clicks">;
16
- declare const impressions: MetricColumn<"impressions">;
17
- declare const ctr: MetricColumn<"ctr">;
18
- declare const position: MetricColumn<"position">;
19
- declare const searchType: QueryParam<"searchType">;
20
- declare function eq<D extends Dimension, V extends DimensionValueMap[D]>(column: Column<D>, value: V): Filter<Record<D, V>>;
21
- declare function eq<P extends QueryParamName, V extends QueryParamValueMap[P]>(param: QueryParam<P>, value: V): Filter<Record<P, V>>;
22
- declare function ne<D extends Dimension>(column: Column<D>, value: DimensionValueMap[D]): Filter<object>;
23
- declare function inArray<D extends Dimension, V extends DimensionValueMap[D]>(column: Column<D>, values: readonly V[]): Filter<Record<D, V>>;
24
- declare function contains<D extends Dimension>(column: Column<D>, pattern: string): Filter<object>;
25
- declare function like<D extends Dimension>(column: Column<D>, pattern: string): Filter<object>;
26
- declare function regex<D extends Dimension>(column: Column<D>, pattern: RegExp | string): Filter<object>;
27
- declare function notRegex<D extends Dimension>(column: Column<D>, pattern: RegExp | string): Filter<object>;
28
- declare function and<F extends Filter<any>[]>(...filters: F): Filter<MergeConstraints<F>>;
29
- declare function or<F extends Filter<any>[]>(...filters: F): Filter<object>;
30
- declare function not<F extends Filter<any>>(filter: F): Filter<object>;
31
- declare function gte<M extends Metric>(column: MetricColumn<M>, value: number): Filter<object>;
32
- declare function gte(column: Column<'date'>, value: string): Filter<object>;
33
- declare function gt<M extends Metric>(column: MetricColumn<M>, value: number): Filter<object>;
34
- declare function gt(column: Column<'date'>, value: string): Filter<object>;
35
- declare function lte<M extends Metric>(column: MetricColumn<M>, value: number): Filter<object>;
36
- declare function lte(column: Column<'date'>, value: string): Filter<object>;
37
- declare function lt<M extends Metric>(column: MetricColumn<M>, value: number): Filter<object>;
38
- declare function lt(column: Column<'date'>, value: string): Filter<object>;
39
- declare function between<M extends Metric>(column: MetricColumn<M>, start: number, end: number): Filter<object>;
40
- declare function between(column: Column<'date'>, start: string, end: string): Filter<object>;
41
- declare function topLevel(column: Column<'page'>): Filter<object>;
42
- declare function normalizeFilter(input?: FilterInput): Filter<any> | undefined;
43
- /**
44
- * Errors-as-values core for {@link normalizeBuilderState}: returns an
45
- * `invalid-builder-state` `QueryError` when the untrusted partner-API body is
46
- * not an object, and an `invalid-filter` `QueryError` when a filter leaf lacks
47
- * its string `dimension`/`operator`, instead of throwing. Also coerces
48
- * alternative `orderBy` shapes into the canonical `{ column, dir }`.
49
- * Receive-edge parse (parse, don't validate), so hosts can map a bad body to a
50
- * 4xx and downstream consumers only ever see the canonical shape.
51
- */
52
- declare function normalizeBuilderStateResult(state: unknown): Result<BuilderState, QueryError>;
53
- declare function normalizeBuilderState(state: unknown): BuilderState;
54
- declare function extractDateRange(input?: FilterInput): {
55
- startDate?: string;
56
- endDate?: string;
57
- };
58
- declare function extractMetricFilters(input?: FilterInput): InternalFilter[];
59
- declare function extractSpecialOperatorFilters(input?: FilterInput): InternalFilter[];
60
- /**
61
- * Pull `searchType` out of a BuilderState filter. Returns undefined for
62
- * missing/invalid shapes — callers treat that as "no scope" (cross-type read).
63
- * Validated against the canonical `SearchTypes` set so unknown strings
64
- * don't reach the engine.
65
- */
66
- declare function extractSearchType(state: BuilderState | undefined | null): SearchType | undefined;
67
- /**
68
- * Errors-as-values core: turns a `BuilderState` into a GSC API request body or
69
- * returns a typed `QueryError` for every modelled bad-query case (missing date
70
- * range, out-of-range row limit / start row, hour/dataState mismatch, illegal
71
- * aggregationType combination). `resolveToBody` is the throwing wrapper over this
72
- * for `.toBody()` and the live-API client paths.
73
- */
74
- declare function resolveToBodyResult(state: BuilderState): Result<GscSearchAnalyticsRequest, QueryError>;
75
- declare function resolveToBody(state: BuilderState): GscSearchAnalyticsRequest;
1
+ import { currentPstDate } from "./utils/dayjs.mjs";
2
+ import { Countries, Country, Device, Devices, SearchType, SearchTypes } from "./constants.mjs";
3
+ import { BuilderState, Column, Dimension, DimensionValueMap, Filter, FilterInput, GSCResult, GSCRow, InternalFilter, JsonFilter, JsonInternalFilter, Metric, MetricColumn, QueryParam, QueryParamName, QueryParamValueMap } from "./types.mjs";
4
+ import { GSCQueryBuilder, gsc } from "./builder.mjs";
5
+ import { clicks, country, ctr, date, device, hour, impressions, page, position, query, queryCanonical, searchAppearance, searchType } from "./columns.mjs";
6
+ import { QueryError, QueryErrorKind, UnresolvableDatasetError, UnsupportedLogicalCapabilityError, isQueryError, queryErrorToException, queryErrors } from "./errors.mjs";
7
+ import { and, between, contains, eq, gt, gte, inArray, like, lt, lte, ne, not, notRegex, or, regex, topLevel } from "./operators.mjs";
8
+ import { ComparisonFilter, LogicalComparisonPlan, LogicalDataset, LogicalDimensionFilter, LogicalMetricFilter, LogicalQueryPlan, PlannerCapabilities, buildLogicalComparisonPlan, buildLogicalComparisonPlanResult, buildLogicalPlan, buildLogicalPlanResult } from "./plan.mjs";
9
+ import { extractDateRange, extractMetricFilters, extractSearchType, extractSpecialOperatorFilters, normalizeBuilderState, normalizeBuilderStateResult, normalizeFilter, resolveToBody, resolveToBodyResult } from "./resolver.mjs";
76
10
  declare function today(): string;
77
11
  declare function daysAgo(n: number): string;
78
12
  export { type BuilderState, type Column, type ComparisonFilter, Countries, type Country, type Device, Devices, type Dimension, type DimensionValueMap, type Filter, type FilterInput, type GSCQueryBuilder, type GSCResult, type GSCRow, type InternalFilter, type JsonFilter, type JsonInternalFilter, type LogicalComparisonPlan, type LogicalDataset, type LogicalDimensionFilter, type LogicalMetricFilter, type LogicalQueryPlan, type Metric, type MetricColumn, type PlannerCapabilities, QueryError, QueryErrorKind, type QueryParam, type QueryParamName, type QueryParamValueMap, type SearchType, SearchTypes, UnresolvableDatasetError, UnsupportedLogicalCapabilityError, and, between, buildLogicalComparisonPlan, buildLogicalComparisonPlanResult, buildLogicalPlan, buildLogicalPlanResult, clicks, contains, country, ctr, currentPstDate, date, daysAgo, device, eq, extractDateRange, extractMetricFilters, extractSearchType, extractSpecialOperatorFilters, gsc, gt, gte, hour, impressions, inArray, isQueryError, like, lt, lte, ne, normalizeBuilderState, normalizeBuilderStateResult, normalizeFilter, not, notRegex, or, page, position, query, queryCanonical, queryErrorToException, queryErrors, regex, resolveToBody, resolveToBodyResult, searchAppearance, searchType, today, topLevel };