@hypequery/datasets 0.28.0 → 0.30.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.
Files changed (72) hide show
  1. package/README.md +18 -0
  2. package/dist/client-contract/build-from-datasets.d.ts +39 -0
  3. package/dist/client-contract/build-from-datasets.d.ts.map +1 -0
  4. package/dist/client-contract/build-from-datasets.js +82 -0
  5. package/dist/client-contract/build-from-deployment.d.ts +13 -0
  6. package/dist/client-contract/build-from-deployment.d.ts.map +1 -1
  7. package/dist/client-contract/build-from-deployment.js +3 -2
  8. package/dist/client-contract/dataset-annotations.d.ts +14 -0
  9. package/dist/client-contract/dataset-annotations.d.ts.map +1 -0
  10. package/dist/client-contract/dataset-annotations.js +27 -0
  11. package/dist/client-contract/dataset-fields.d.ts +24 -0
  12. package/dist/client-contract/dataset-fields.d.ts.map +1 -0
  13. package/dist/client-contract/dataset-fields.js +109 -0
  14. package/dist/client-contract/deployment-fields.d.ts +4 -3
  15. package/dist/client-contract/deployment-fields.d.ts.map +1 -1
  16. package/dist/client-contract/deployment-fields.js +15 -12
  17. package/dist/client-contract/deployment-profile.d.ts +9 -0
  18. package/dist/client-contract/deployment-profile.d.ts.map +1 -1
  19. package/dist/client-contract/deployment-profile.js +10 -6
  20. package/dist/execution-capabilities.json +4 -4
  21. package/dist/executor.d.ts +33 -1
  22. package/dist/executor.d.ts.map +1 -1
  23. package/dist/executor.js +59 -0
  24. package/dist/index.d.ts +4 -2
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +1 -0
  27. package/dist/internal.d.ts +1 -0
  28. package/dist/internal.d.ts.map +1 -1
  29. package/dist/internal.js +1 -0
  30. package/dist/metric-query-engine.d.ts +9 -0
  31. package/dist/metric-query-engine.d.ts.map +1 -1
  32. package/dist/metric-query-engine.js +25 -15
  33. package/dist/protocol-adapter.d.ts.map +1 -1
  34. package/dist/protocol-adapter.js +6 -0
  35. package/dist/query-builder-protocol.d.ts +32 -0
  36. package/dist/query-builder-protocol.d.ts.map +1 -1
  37. package/dist/semantic-query-schema.d.ts.map +1 -1
  38. package/dist/semantic-query-schema.js +19 -11
  39. package/dist/types.d.ts +58 -7
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/utils/compile-dataset-query.d.ts +9 -3
  42. package/dist/utils/compile-dataset-query.d.ts.map +1 -1
  43. package/dist/utils/compile-dataset-query.js +11 -9
  44. package/dist/utils/dataset-filter-types.d.ts +35 -10
  45. package/dist/utils/dataset-filter-types.d.ts.map +1 -1
  46. package/dist/utils/dataset-query-validation.d.ts.map +1 -1
  47. package/dist/utils/dataset-query-validation.js +5 -3
  48. package/dist/utils/effective-filters.d.ts +27 -0
  49. package/dist/utils/effective-filters.d.ts.map +1 -0
  50. package/dist/utils/effective-filters.js +36 -0
  51. package/dist/utils/enforced-constraints.d.ts.map +1 -1
  52. package/dist/utils/enforced-constraints.js +5 -3
  53. package/dist/utils/metric-query-validation.d.ts.map +1 -1
  54. package/dist/utils/metric-query-validation.js +5 -3
  55. package/dist/utils/portable-semantic-query.d.ts.map +1 -1
  56. package/dist/utils/portable-semantic-query.js +11 -0
  57. package/dist/utils/relationship-measure-sql.d.ts.map +1 -1
  58. package/dist/utils/relationship-measure-sql.js +4 -2
  59. package/dist/utils/relationship-validation.d.ts.map +1 -1
  60. package/dist/utils/relationship-validation.js +5 -4
  61. package/dist/utils/semantic-stream.d.ts +6 -0
  62. package/dist/utils/semantic-stream.d.ts.map +1 -0
  63. package/dist/utils/semantic-stream.js +17 -0
  64. package/dist/utils/statement-runner.d.ts +31 -0
  65. package/dist/utils/statement-runner.d.ts.map +1 -0
  66. package/dist/utils/statement-runner.js +43 -0
  67. package/dist/utils/stream-ceiling.d.ts +10 -0
  68. package/dist/utils/stream-ceiling.d.ts.map +1 -0
  69. package/dist/utils/stream-ceiling.js +21 -0
  70. package/dist/utils/time-measure-axis-sql.d.ts.map +1 -1
  71. package/dist/utils/time-measure-axis-sql.js +4 -1
  72. package/package.json +6 -6
package/README.md CHANGED
@@ -115,6 +115,24 @@ for module boundaries and verification requirements, and the
115
115
 
116
116
  Apache-2.0.
117
117
 
118
+ ## Client contracts from a deployment
119
+
120
+ `buildClientContract(deployment, options)` turns a deployment contract (for
121
+ example `publishToCloud`'s output) into the hashed client contract
122
+ `hypequery generate:client` reads. `having` and a per-request `timezone` are
123
+ off unless the host's route passes them through to the data plane, since a
124
+ route that builds its operation from a fixed list of fields would drop them.
125
+ A host that passes them through opts in:
126
+
127
+ ```ts
128
+ buildClientContract(deployment, {
129
+ capabilities: { having: true, timezone: true },
130
+ });
131
+ ```
132
+
133
+ Capabilities are part of each endpoint's `schemaHash`; changing them means
134
+ regenerating clients.
135
+
118
136
  ## Public client descriptor schemas
119
137
 
120
138
  `buildClientContractQuerySchemas(contract)` validates an RFC 0018 signed client
@@ -0,0 +1,39 @@
1
+ import { type PreparedProtocolClientContract } from '@hypequery/protocol';
2
+ import type { AnyDatasetInstance, MetricRef } from '../types.js';
3
+ import { type ClientContractProfile } from './deployment-profile.js';
4
+ /** One logical endpoint a host serves: a dataset query, or one metric of a dataset. */
5
+ export interface DatasetClientEndpoint {
6
+ /** The dataset queried, or the dataset the metric reads. */
7
+ readonly dataset: AnyDatasetInstance;
8
+ /** The absolute route the host serves this endpoint at, below `mountPath`. */
9
+ readonly path: string;
10
+ /** For a metric endpoint, the metric it serves. Its rows carry the value under the metric's name. */
11
+ readonly metric?: MetricRef;
12
+ /** A metric endpoint's export ID, such as its route key; the metric's name by default. */
13
+ readonly name?: string;
14
+ /**
15
+ * Ceilings the host enforces for this endpoint; defaults mirror Python's
16
+ * ClientQueryProfile. The export only ever narrows them by the dataset's limits.
17
+ */
18
+ readonly profile?: ClientContractProfile;
19
+ }
20
+ export interface BuildDatasetClientContractOptions {
21
+ /**
22
+ * Trusted mount prefix, such as `/v1`: absolute, no trailing slash. Never a
23
+ * proxy or request header; the host knows how it is mounted.
24
+ */
25
+ readonly mountPath?: string;
26
+ /** `authorized` is a caller's view: the host passes only that caller's endpoints. */
27
+ readonly view?: 'build' | 'authorized';
28
+ }
29
+ /**
30
+ * The client contract for endpoints a host serves from dataset definitions:
31
+ * typed fields, routes and schema hashes that `hypequery generate:client`
32
+ * turns into React types and a route manifest. Pure: no network, no execution.
33
+ * Mirrors Python's `export_client_contract`, so an equivalent definition
34
+ * exports the same contract in either language.
35
+ *
36
+ * The host owns the routes and must enforce the advertised profile on them.
37
+ */
38
+ export declare function buildDatasetClientContract(endpoints: readonly DatasetClientEndpoint[], options?: BuildDatasetClientContractOptions): PreparedProtocolClientContract;
39
+ //# sourceMappingURL=build-from-datasets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-from-datasets.d.ts","sourceRoot":"","sources":["../../src/client-contract/build-from-datasets.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIjE,OAAO,EAAyD,KAAK,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAE5H,uFAAuF;AACvF,MAAM,WAAW,qBAAqB;IACpC,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qGAAqG;IACrG,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAC5B,0FAA0F;IAC1F,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;CAC1C;AAED,MAAM,WAAW,iCAAiC;IAChD;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,qFAAqF;IACrF,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;CACxC;AA2DD;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,SAAS,qBAAqB,EAAE,EAC3C,OAAO,GAAE,iCAAsC,GAC9C,8BAA8B,CAWhC"}
@@ -0,0 +1,82 @@
1
+ import { prepareProtocolClientContract, } from '@hypequery/protocol';
2
+ import { SUPPORTED_TIME_GRAINS } from '../constants.js';
3
+ import { baseMeasureNames } from '../utils/dataset-measures.js';
4
+ import { datasetEndpointAnnotations } from './dataset-annotations.js';
5
+ import { datasetPublicFields } from './dataset-fields.js';
6
+ import { narrowClientQueryLimits, resolveClientContractProfile } from './deployment-profile.js';
7
+ function endpointDescriptor(endpoint, mountPath) {
8
+ const { dataset, metric } = endpoint;
9
+ if (!endpoint.path.startsWith('/')) {
10
+ throw new Error(`Client export: the endpoint for "${dataset.name}" needs an absolute path.`);
11
+ }
12
+ if (metric !== undefined && metric.dataset !== dataset) {
13
+ throw new Error(`Client export: metric "${metric.name}" does not read dataset "${dataset.name}".`);
14
+ }
15
+ const fields = datasetPublicFields(dataset);
16
+ const { dimensions, filters } = fields;
17
+ const id = metric === undefined ? dataset.name : endpoint.name ?? metric.name;
18
+ if (metric !== undefined && id === dataset.name) {
19
+ throw new Error(`Client export: metric "${id}" needs an export ID other than its dataset's name.`);
20
+ }
21
+ // A metric's rows carry its one value under the metric's name.
22
+ const measures = metric === undefined
23
+ ? fields.measures
24
+ : { [metric.name]: { wireType: 'string', nullable: true, having: false } };
25
+ // Rows carry the time bucket as `period`, so a field of that name would collide.
26
+ if (dataset.timeKey !== undefined && (Object.hasOwn(dimensions, 'period') || Object.hasOwn(measures, 'period'))) {
27
+ throw new Error(`Client export: dataset "${dataset.name}" has a field named "period", which its time bucket uses. Rename it.`);
28
+ }
29
+ const profile = resolveClientContractProfile(endpoint.profile);
30
+ const limits = narrowClientQueryLimits(dataset.limits, undefined, profile);
31
+ const node = {
32
+ id,
33
+ kind: metric === undefined ? 'dataset' : 'metric',
34
+ dataset: dataset.name,
35
+ path: mountPath + endpoint.path,
36
+ dimensions,
37
+ measures,
38
+ filters,
39
+ metadata: true,
40
+ limits,
41
+ time: dataset.timeKey === undefined ? null : {
42
+ grains: [...(dataset.timeGrains ?? SUPPORTED_TIME_GRAINS)].sort(),
43
+ defaultTimezone: profile.defaultTimezone,
44
+ timezone: true,
45
+ periodFormat: 'calendar-date-or-local-datetime-v1',
46
+ },
47
+ };
48
+ if (metric === undefined) {
49
+ // An endpoint's default selection is the base measures it can serve.
50
+ const defaultMeasures = baseMeasureNames(dataset.measures).filter(name => Object.hasOwn(measures, name));
51
+ if (defaultMeasures.length > limits.maxMeasures) {
52
+ throw new Error(`Client export: dataset "${dataset.name}" selects ${defaultMeasures.length} measures by default, `
53
+ + `more than its measure budget of ${limits.maxMeasures}. Raise limits.maxMeasures.`);
54
+ }
55
+ node.defaultMeasures = defaultMeasures;
56
+ }
57
+ const annotations = datasetEndpointAnnotations(dataset, Object.keys(dimensions), Object.keys(measures), metric);
58
+ if (annotations)
59
+ node.annotations = annotations;
60
+ return node;
61
+ }
62
+ /**
63
+ * The client contract for endpoints a host serves from dataset definitions:
64
+ * typed fields, routes and schema hashes that `hypequery generate:client`
65
+ * turns into React types and a route manifest. Pure: no network, no execution.
66
+ * Mirrors Python's `export_client_contract`, so an equivalent definition
67
+ * exports the same contract in either language.
68
+ *
69
+ * The host owns the routes and must enforce the advertised profile on them.
70
+ */
71
+ export function buildDatasetClientContract(endpoints, options = {}) {
72
+ const mountPath = options.mountPath ?? '';
73
+ if (mountPath && (!mountPath.startsWith('/') || mountPath.endsWith('/'))) {
74
+ throw new Error('Client export: mountPath must be empty or an absolute path without a trailing slash.');
75
+ }
76
+ return prepareProtocolClientContract({
77
+ kind: 'hypequery-client-contract',
78
+ version: 1,
79
+ view: options.view ?? 'build',
80
+ endpoints: endpoints.map(endpoint => endpointDescriptor(endpoint, mountPath)),
81
+ });
82
+ }
@@ -14,6 +14,19 @@ export interface BuildClientContractOptions {
14
14
  readonly view?: 'build' | 'authorized';
15
15
  /** Which published datasets to advertise; every one by default. */
16
16
  readonly include?: (dataset: ProtocolDeploymentDataset) => boolean;
17
+ /**
18
+ * Request features the host's route passes through to the data plane. A
19
+ * route may build its operation from a fixed list of fields and drop the
20
+ * rest, so `having` and a per-request `timezone` stay off unless the host
21
+ * turns them on; advertising one the host drops would return the wrong rows.
22
+ */
23
+ readonly capabilities?: ClientContractCapabilities;
24
+ }
25
+ export interface ClientContractCapabilities {
26
+ /** Accepts `having` predicates on measures. */
27
+ readonly having?: boolean;
28
+ /** Accepts a per-request `timezone` for time buckets. */
29
+ readonly timezone?: boolean;
17
30
  }
18
31
  /**
19
32
  * The client contract for a deployment's published datasets: typed fields,
@@ -1 +1 @@
1
- {"version":3,"file":"build-from-deployment.d.ts","sourceRoot":"","sources":["../../src/client-contract/build-from-deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC/B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAmD,KAAK,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEtH,MAAM,WAAW,0BAA0B;IACzC,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,uGAAuG;IACvG,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IACvC,mEAAmE;IACnE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,yBAAyB,KAAK,OAAO,CAAC;CACpE;AA2DD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,0BAA0B,EACpC,OAAO,GAAE,0BAA+B,GACvC,8BAA8B,CAchC"}
1
+ {"version":3,"file":"build-from-deployment.d.ts","sourceRoot":"","sources":["../../src/client-contract/build-from-deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC/B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAmD,KAAK,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEtH,MAAM,WAAW,0BAA0B;IACzC,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,uGAAuG;IACvG,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IACvC,mEAAmE;IACnE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,yBAAyB,KAAK,OAAO,CAAC;IACnE;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,0BAA0B,CAAC;CACpD;AAED,MAAM,WAAW,0BAA0B;IACzC,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AA4DD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,0BAA0B,EACpC,OAAO,GAAE,0BAA+B,GACvC,8BAA8B,CAchC"}
@@ -11,7 +11,8 @@ function endpointPath(dataset, options) {
11
11
  return (options.mountPath ?? '') + path;
12
12
  }
13
13
  function endpointDescriptor(dataset, options, profile) {
14
- const { dimensions, measures, filters } = publicFields(dataset);
14
+ const capabilities = options.capabilities ?? {};
15
+ const { dimensions, measures, filters } = publicFields(dataset, capabilities);
15
16
  // Rows carry the time bucket as `period`, so a field of that name would collide.
16
17
  if (dataset.timeField !== undefined && (Object.hasOwn(dimensions, 'period') || Object.hasOwn(measures, 'period'))) {
17
18
  throw new Error(`Client export: dataset "${dataset.name}" has a field named "period", which its time bucket uses. Rename it.`);
@@ -45,7 +46,7 @@ function endpointDescriptor(dataset, options, profile) {
45
46
  time: dataset.timeField === undefined ? null : {
46
47
  grains: [...PORTABLE_TIME_GRAINS],
47
48
  defaultTimezone: profile.defaultTimezone,
48
- timezone: true,
49
+ timezone: capabilities.timezone === true,
49
50
  periodFormat: 'calendar-date-or-local-datetime-v1',
50
51
  },
51
52
  defaultMeasures,
@@ -0,0 +1,14 @@
1
+ import type { ClientEndpointAnnotations } from '@hypequery/protocol';
2
+ import type { AnyDatasetInstance } from '../types.js';
3
+ interface Described {
4
+ readonly label?: string;
5
+ readonly description?: string;
6
+ }
7
+ /**
8
+ * Group text from the dataset; field text for each advertised dimension and
9
+ * measure. A metric endpoint's sole measure key is its public alias, so its
10
+ * text comes from `metric`, the handle it serves.
11
+ */
12
+ export declare function datasetEndpointAnnotations(dataset: AnyDatasetInstance, dimensions: readonly string[], measures: readonly string[], metric?: Described): ClientEndpointAnnotations | undefined;
13
+ export {};
14
+ //# sourceMappingURL=dataset-annotations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset-annotations.d.ts","sourceRoot":"","sources":["../../src/client-contract/dataset-annotations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAyB,MAAM,qBAAqB,CAAC;AAC5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtD,UAAU,SAAS;IACjB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAUD;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,kBAAkB,EAC3B,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,MAAM,CAAC,EAAE,SAAS,GACjB,yBAAyB,GAAG,SAAS,CAWvC"}
@@ -0,0 +1,27 @@
1
+ import { annotationText } from './deployment-annotations.js';
2
+ function fieldAnnotation(definition) {
3
+ if (definition === undefined)
4
+ return undefined;
5
+ const label = annotationText(definition.label);
6
+ const description = annotationText(definition.description);
7
+ if (label === undefined && description === undefined)
8
+ return undefined;
9
+ return { ...(label !== undefined ? { label } : {}), ...(description !== undefined ? { description } : {}) };
10
+ }
11
+ /**
12
+ * Group text from the dataset; field text for each advertised dimension and
13
+ * measure. A metric endpoint's sole measure key is its public alias, so its
14
+ * text comes from `metric`, the handle it serves.
15
+ */
16
+ export function datasetEndpointAnnotations(dataset, dimensions, measures, metric) {
17
+ const fields = Object.fromEntries([
18
+ ...dimensions.map(key => [key, fieldAnnotation(dataset.dimensions[key])]),
19
+ ...measures.map(key => [key, fieldAnnotation(metric ?? dataset.measures[key])]),
20
+ ].filter((entry) => entry[1] !== undefined));
21
+ const description = annotationText(dataset.description);
22
+ const result = {
23
+ ...(description !== undefined ? { description } : {}),
24
+ ...(Object.keys(fields).length ? { fields } : {}),
25
+ };
26
+ return Object.keys(result).length ? result : undefined;
27
+ }
@@ -0,0 +1,24 @@
1
+ import type { ClientDimension, ClientFilter, ClientMeasure } from '@hypequery/protocol';
2
+ import type { AnyDatasetInstance, DatasetMeasureDefinition, DimensionDefinition, SemanticFilterDefinition } from '../types.js';
3
+ /** Local fields have unknown nullability; the client contract says so rather than guess. */
4
+ export declare function datasetDimensionDescriptor(dimension: DimensionDefinition): ClientDimension;
5
+ /**
6
+ * Base and derived measures are served by a plain query. Window and shift
7
+ * measures need a time axis the client profile does not carry, so they, and
8
+ * formulas over them, are not advertised.
9
+ */
10
+ export declare function servableMeasure(dataset: AnyDatasetInstance, name: string, path?: Set<string>): boolean;
11
+ /** `having` compares numbers, so ordered aggregations over non-numeric fields can't take it. */
12
+ export declare function datasetMeasureDescriptor(dataset: AnyDatasetInstance, measure: DatasetMeasureDefinition): ClientMeasure;
13
+ export declare function datasetFilterDescriptor(dimension: DimensionDefinition, filter: SemanticFilterDefinition): ClientFilter | null;
14
+ /**
15
+ * The fields one dataset endpoint advertises, resolved from the definition as
16
+ * Python's `public_fields` does with `related=()`. Relationship fields are not
17
+ * exported yet, so a measure whose fixed filters cross a relationship is left out.
18
+ */
19
+ export declare function datasetPublicFields(dataset: AnyDatasetInstance): {
20
+ dimensions: Record<string, ClientDimension>;
21
+ measures: Record<string, ClientMeasure>;
22
+ filters: Record<string, ClientFilter>;
23
+ };
24
+ //# sourceMappingURL=dataset-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset-fields.d.ts","sourceRoot":"","sources":["../../src/client-contract/dataset-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAExF,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAUrB,4FAA4F;AAC5F,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,mBAAmB,GAAG,eAAe,CAS1F;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,cAAoB,GAAG,OAAO,CAU5G;AAED,gGAAgG;AAChG,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,wBAAwB,GAAG,aAAa,CAQtH;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,wBAAwB,GAAG,YAAY,GAAG,IAAI,CAO7H;AA2BD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG;IAChE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACvC,CAkBA"}
@@ -0,0 +1,109 @@
1
+ import { SEMANTIC_FILTER_OPERATORS } from '../constants.js';
2
+ import { isBaseMeasure, isDerivedMeasure } from '../utils/dataset-measures.js';
3
+ // As Python's builder: booleans compare by equality and membership only.
4
+ // Null checks stay: a boolean column can hold NULL (RFC 0023).
5
+ const BOOLEAN_OPERATORS = new Set(['eq', 'neq', 'in', 'notIn', 'isNull', 'isNotNull']);
6
+ const ORDERED_AGGREGATIONS = new Set(['min', 'max', 'argMin', 'argMax']);
7
+ /** Stored states whose merged value is the stored value itself, which may not be a number. */
8
+ const ORDERED_STATES = new Set(['min', 'max', 'any', 'anyLast']);
9
+ /** Local fields have unknown nullability; the client contract says so rather than guess. */
10
+ export function datasetDimensionDescriptor(dimension) {
11
+ const type = dimension.fieldType;
12
+ return {
13
+ type,
14
+ wireType: type === 'number' ? 'number-or-string' : type === 'boolean' ? 'boolean' : 'string',
15
+ nullable: 'unknown',
16
+ groupable: dimension.groupable !== false,
17
+ orderable: dimension.groupable !== false,
18
+ };
19
+ }
20
+ /**
21
+ * Base and derived measures are served by a plain query. Window and shift
22
+ * measures need a time axis the client profile does not carry, so they, and
23
+ * formulas over them, are not advertised.
24
+ */
25
+ export function servableMeasure(dataset, name, path = new Set()) {
26
+ // `path` holds only the current chain, so a measure used twice is not a cycle.
27
+ if (!Object.hasOwn(dataset.measures, name) || path.has(name))
28
+ return false;
29
+ const measure = dataset.measures[name];
30
+ if (isBaseMeasure(measure))
31
+ return true;
32
+ if (!isDerivedMeasure(measure))
33
+ return false;
34
+ path.add(name);
35
+ const servable = Object.values(measure.uses).every(use => servableMeasure(dataset, use, path));
36
+ path.delete(name);
37
+ return servable;
38
+ }
39
+ /** `having` compares numbers, so ordered aggregations over non-numeric fields can't take it. */
40
+ export function datasetMeasureDescriptor(dataset, measure) {
41
+ if (!isBaseMeasure(measure))
42
+ return { wireType: 'string', nullable: true, having: true };
43
+ if (measure.aggregation === 'merge') {
44
+ return { wireType: 'string', nullable: true, having: !ORDERED_STATES.has(String(measure.stateFunction)) };
45
+ }
46
+ if (!ORDERED_AGGREGATIONS.has(measure.aggregation))
47
+ return { wireType: 'string', nullable: true, having: true };
48
+ const dimension = Object.hasOwn(dataset.dimensions, measure.field) ? dataset.dimensions[measure.field] : undefined;
49
+ return { wireType: 'string', nullable: true, having: dimension?.fieldType === 'number' };
50
+ }
51
+ export function datasetFilterDescriptor(dimension, filter) {
52
+ const type = dimension.fieldType;
53
+ // An undeclared list allows every value operator; null checks must be named (RFC 0023).
54
+ const operators = [...new Set((filter.operators ?? SEMANTIC_FILTER_OPERATORS).filter(operator => type === 'boolean'
55
+ ? BOOLEAN_OPERATORS.has(operator)
56
+ : type !== 'number' || operator !== 'like'))].sort();
57
+ return operators.length ? { type, operators } : null;
58
+ }
59
+ /** Tenant identities come from the caller's credential, never from request predicates. */
60
+ function requestFilter(dataset, field) {
61
+ return dataset.tenantKey === undefined || (dataset.dimensions[field].column ?? field) !== dataset.tenantKey;
62
+ }
63
+ /** The fields a measure's fixed filters read, through any derived dependencies. */
64
+ function measureFilterFields(dataset, name) {
65
+ const pending = [name];
66
+ const seen = new Set();
67
+ const fields = [];
68
+ while (pending.length) {
69
+ const current = pending.pop();
70
+ if (seen.has(current) || !Object.hasOwn(dataset.measures, current))
71
+ continue;
72
+ seen.add(current);
73
+ const measure = dataset.measures[current];
74
+ if (isDerivedMeasure(measure))
75
+ pending.push(...Object.values(measure.uses));
76
+ else if (isBaseMeasure(measure)) {
77
+ for (const filter of measure.filters ?? []) {
78
+ fields.push(Object.hasOwn(dataset.filters, filter.field) ? dataset.filters[filter.field].field : filter.field);
79
+ }
80
+ }
81
+ }
82
+ return fields;
83
+ }
84
+ /**
85
+ * The fields one dataset endpoint advertises, resolved from the definition as
86
+ * Python's `public_fields` does with `related=()`. Relationship fields are not
87
+ * exported yet, so a measure whose fixed filters cross a relationship is left out.
88
+ */
89
+ export function datasetPublicFields(dataset) {
90
+ // Object.fromEntries defines each name as an own key, `__proto__` included.
91
+ const dimensions = Object.fromEntries(Object.entries(dataset.dimensions)
92
+ .map(([name, dimension]) => [name, datasetDimensionDescriptor(dimension)]));
93
+ const measures = Object.fromEntries(Object.entries(dataset.measures)
94
+ .filter(([name]) => servableMeasure(dataset, name)
95
+ && measureFilterFields(dataset, name).every(field => !field.includes('.')))
96
+ .map(([name, measure]) => [name, datasetMeasureDescriptor(dataset, measure)]));
97
+ const filters = Object.fromEntries(Object.entries(dataset.filters).flatMap(([name, filter]) => {
98
+ if (filter.field.includes('.'))
99
+ return [];
100
+ if (!Object.hasOwn(dataset.dimensions, filter.field)) {
101
+ throw new Error(`Client export: filter "${dataset.name}.${name}" references unknown dimension "${filter.field}".`);
102
+ }
103
+ if (!requestFilter(dataset, filter.field))
104
+ return [];
105
+ const descriptor = datasetFilterDescriptor(dataset.dimensions[filter.field], filter);
106
+ return descriptor ? [[name, descriptor]] : [];
107
+ }));
108
+ return { dimensions, measures, filters };
109
+ }
@@ -1,8 +1,9 @@
1
1
  import type { ClientDimension, ClientFilter, ClientMeasure, ProtocolDatasetDimension, ProtocolDatasetFilter, ProtocolDeploymentDataset, ProtocolDeploymentMeasure } from '@hypequery/protocol';
2
+ import type { ClientContractCapabilities } from './build-from-deployment.js';
2
3
  /** Local fields have unknown nullability; the client contract says so rather than guess. */
3
4
  export declare function dimensionDescriptor(dimension: ProtocolDatasetDimension): ClientDimension;
4
- /** `having` compares numbers, so ordered aggregations over non-numeric fields can't take it. */
5
- export declare function measureDescriptor(dataset: ProtocolDeploymentDataset, measure: ProtocolDeploymentMeasure): ClientMeasure;
5
+ /** Every measure's value is a decimal string; `having` only where the host executes it and it compares numbers. */
6
+ export declare function measureDescriptor(dataset: ProtocolDeploymentDataset, measure: ProtocolDeploymentMeasure, capabilities: ClientContractCapabilities): ClientMeasure;
6
7
  export declare function filterDescriptor(dimension: ProtocolDatasetDimension, filter: ProtocolDatasetFilter): ClientFilter | null;
7
8
  /** Tenant identities come from the caller's credential, never from request predicates. */
8
9
  export declare function requestFilter(dataset: ProtocolDeploymentDataset, dimension: ProtocolDatasetDimension): boolean;
@@ -11,7 +12,7 @@ export declare function requestFilter(dataset: ProtocolDeploymentDataset, dimens
11
12
  * exported yet, matching Python's default (`related=()`), so a measure whose
12
13
  * fixed filters cross a relationship is left out rather than advertised.
13
14
  */
14
- export declare function publicFields(dataset: ProtocolDeploymentDataset): {
15
+ export declare function publicFields(dataset: ProtocolDeploymentDataset, capabilities: ClientContractCapabilities): {
15
16
  dimensions: Record<string, ClientDimension>;
16
17
  measures: Record<string, ClientMeasure>;
17
18
  filters: Record<string, ClientFilter>;
@@ -1 +1 @@
1
- {"version":3,"file":"deployment-fields.d.ts","sourceRoot":"","sources":["../../src/client-contract/deployment-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACb,wBAAwB,EACxB,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EAE1B,MAAM,qBAAqB,CAAC;AAQ7B,4FAA4F;AAC5F,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,wBAAwB,GAAG,eAAe,CAQxF;AAED,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,yBAAyB,GAAG,aAAa,CAUvH;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,wBAAwB,EAAE,MAAM,EAAE,qBAAqB,GAAG,YAAY,GAAG,IAAI,CAKxH;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,OAAO,EAAE,yBAAyB,EAAE,SAAS,EAAE,wBAAwB,GAAG,OAAO,CAI9G;AAmCD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,yBAAyB,GAAG;IAChE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACvC,CAkBA"}
1
+ {"version":3,"file":"deployment-fields.d.ts","sourceRoot":"","sources":["../../src/client-contract/deployment-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACb,wBAAwB,EACxB,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EAE1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAS7E,4FAA4F;AAC5F,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,wBAAwB,GAAG,eAAe,CAQxF;AAWD,mHAAmH;AACnH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,yBAAyB,EAClC,YAAY,EAAE,0BAA0B,GACvC,aAAa,CAEf;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,wBAAwB,EAAE,MAAM,EAAE,qBAAqB,GAAG,YAAY,GAAG,IAAI,CAKxH;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,OAAO,EAAE,yBAAyB,EAAE,SAAS,EAAE,wBAAwB,GAAG,OAAO,CAI9G;AAmCD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,yBAAyB,EAAE,YAAY,EAAE,0BAA0B,GAAG;IAC1G,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACvC,CAkBA"}
@@ -1,5 +1,6 @@
1
1
  // As Python's builder: booleans compare by equality and membership only.
2
- const BOOLEAN_OPERATORS = new Set(['eq', 'neq', 'in', 'notIn']);
2
+ // Null checks stay: a boolean column can hold NULL (RFC 0023).
3
+ const BOOLEAN_OPERATORS = new Set(['eq', 'neq', 'in', 'notIn', 'isNull', 'isNotNull']);
3
4
  const ORDERED_AGGREGATIONS = new Set(['min', 'max', 'argMin', 'argMax']);
4
5
  /** Stored states whose merged value is the stored value itself, which may not be a number. */
5
6
  const ORDERED_STATES = new Set(['min', 'max', 'any', 'anyLast']);
@@ -14,17 +15,19 @@ export function dimensionDescriptor(dimension) {
14
15
  };
15
16
  }
16
17
  /** `having` compares numbers, so ordered aggregations over non-numeric fields can't take it. */
17
- export function measureDescriptor(dataset, measure) {
18
+ function havingAllowed(dataset, measure) {
18
19
  if ('kind' in measure)
19
- return { wireType: 'string', nullable: true, having: true };
20
- if (measure.aggregation === 'merge') {
21
- return { wireType: 'string', nullable: true, having: !ORDERED_STATES.has(String(measure.stateFunction)) };
22
- }
23
- if (!ORDERED_AGGREGATIONS.has(measure.aggregation)) {
24
- return { wireType: 'string', nullable: true, having: true };
25
- }
20
+ return true;
21
+ if (measure.aggregation === 'merge')
22
+ return !ORDERED_STATES.has(String(measure.stateFunction));
23
+ if (!ORDERED_AGGREGATIONS.has(measure.aggregation))
24
+ return true;
26
25
  const dimension = dataset.dimensions.find(item => item.name === measure.field);
27
- return { wireType: 'string', nullable: true, having: dimension?.type === 'number' };
26
+ return dimension?.type === 'number';
27
+ }
28
+ /** Every measure's value is a decimal string; `having` only where the host executes it and it compares numbers. */
29
+ export function measureDescriptor(dataset, measure, capabilities) {
30
+ return { wireType: 'string', nullable: true, having: capabilities.having === true && havingAllowed(dataset, measure) };
28
31
  }
29
32
  export function filterDescriptor(dimension, filter) {
30
33
  const operators = [...new Set(filter.operators.filter(operator => dimension.type === 'boolean'
@@ -80,11 +83,11 @@ function measureFilterFields(dataset, name) {
80
83
  * exported yet, matching Python's default (`related=()`), so a measure whose
81
84
  * fixed filters cross a relationship is left out rather than advertised.
82
85
  */
83
- export function publicFields(dataset) {
86
+ export function publicFields(dataset, capabilities) {
84
87
  const dimensions = Object.fromEntries(dataset.dimensions.map(dimension => [dimension.name, dimensionDescriptor(dimension)]));
85
88
  const measures = Object.fromEntries(dataset.measures
86
89
  .filter(measure => measureFilterFields(dataset, measure.name).every(field => !field.includes('.')))
87
- .map(measure => [measure.name, measureDescriptor(dataset, measure)]));
90
+ .map(measure => [measure.name, measureDescriptor(dataset, measure, capabilities)]));
88
91
  // Built with Object.fromEntries, as above: assigning a key such as
89
92
  // `__proto__` would set the prototype instead of adding an entry.
90
93
  const filters = Object.fromEntries(dataset.filters.flatMap((filter) => {
@@ -17,6 +17,15 @@ export interface ClientContractProfile {
17
17
  readonly defaultTimezone?: string;
18
18
  }
19
19
  export declare function resolveClientContractProfile(profile?: ClientContractProfile): Required<ClientContractProfile>;
20
+ /** A definition's own query ceilings, as datasets and deployment datasets both carry them. */
21
+ export interface ClientLimitCeilings {
22
+ readonly maxResultSize?: number;
23
+ readonly maxDimensions?: number;
24
+ readonly maxMeasures?: number;
25
+ readonly maxFilters?: number;
26
+ }
27
+ /** Intersect the profile with a definition's ceilings and an endpoint's page cap; never widen them. */
28
+ export declare function narrowClientQueryLimits(ceilings: ClientLimitCeilings | undefined, endpointMaxLimit: number | undefined, profile: Required<ClientContractProfile>): ClientQueryLimits;
20
29
  /** Intersect the profile with the dataset's own ceilings; never widen them. */
21
30
  export declare function clientQueryLimits(dataset: ProtocolDeploymentDataset, profile: Required<ClientContractProfile>): ClientQueryLimits;
22
31
  //# sourceMappingURL=deployment-profile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deployment-profile.d.ts","sourceRoot":"","sources":["../../src/client-contract/deployment-profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAExF;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,gDAAgD;IAChD,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAcD,wBAAgB,4BAA4B,CAAC,OAAO,GAAE,qBAA0B,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAEjH;AAID,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,iBAAiB,CAYjI"}
1
+ {"version":3,"file":"deployment-profile.d.ts","sourceRoot":"","sources":["../../src/client-contract/deployment-profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAExF;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,gDAAgD;IAChD,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAcD,wBAAgB,4BAA4B,CAAC,OAAO,GAAE,qBAA0B,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAEjH;AAID,8FAA8F;AAC9F,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,uGAAuG;AACvG,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,mBAAmB,GAAG,SAAS,EACzC,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GACvC,iBAAiB,CAYnB;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,iBAAiB,CAEjI"}
@@ -13,17 +13,21 @@ export function resolveClientContractProfile(profile = {}) {
13
13
  return { ...DEFAULT_PROFILE, ...Object.fromEntries(Object.entries(profile).filter(([, value]) => value !== undefined)) };
14
14
  }
15
15
  const narrower = (ceiling, value) => value === undefined ? ceiling : Math.min(ceiling, value);
16
- /** Intersect the profile with the dataset's own ceilings; never widen them. */
17
- export function clientQueryLimits(dataset, profile) {
18
- const maxLimit = narrower(narrower(profile.maxLimit, dataset.limits?.maxResultSize), dataset.endpoint?.maxLimit);
16
+ /** Intersect the profile with a definition's ceilings and an endpoint's page cap; never widen them. */
17
+ export function narrowClientQueryLimits(ceilings, endpointMaxLimit, profile) {
18
+ const maxLimit = narrower(narrower(profile.maxLimit, ceilings?.maxResultSize), endpointMaxLimit);
19
19
  return {
20
20
  defaultLimit: Math.min(profile.defaultLimit, maxLimit),
21
21
  maxLimit,
22
22
  maxOffset: profile.maxOffset,
23
- maxDimensions: narrower(profile.maxDimensions, dataset.limits?.maxDimensions),
24
- maxMeasures: narrower(profile.maxMeasures, dataset.limits?.maxMeasures),
25
- maxPredicates: narrower(profile.maxPredicates, dataset.limits?.maxFilters),
23
+ maxDimensions: narrower(profile.maxDimensions, ceilings?.maxDimensions),
24
+ maxMeasures: narrower(profile.maxMeasures, ceilings?.maxMeasures),
25
+ maxPredicates: narrower(profile.maxPredicates, ceilings?.maxFilters),
26
26
  maxOrderBy: profile.maxOrderBy,
27
27
  maxFilterValues: profile.maxFilterValues,
28
28
  };
29
29
  }
30
+ /** Intersect the profile with the dataset's own ceilings; never widen them. */
31
+ export function clientQueryLimits(dataset, profile) {
32
+ return narrowClientQueryLimits(dataset.limits, dataset.endpoint?.maxLimit, profile);
33
+ }
@@ -4,10 +4,10 @@
4
4
  "features": [
5
5
  { "feature": "baseMeasures", "protocolVersions": [2, 3], "typescript": { "local": true, "publish": true }, "python": { "local": true, "publish": true }, "cloud": true },
6
6
  { "feature": "derivedMeasures", "protocolVersions": [2, 3], "typescript": { "local": true, "publish": true }, "python": { "local": true, "publish": true }, "cloud": true },
7
- { "feature": "segments", "protocolVersions": [3], "typescript": { "local": true, "publish": false }, "python": { "local": false, "publish": false }, "cloud": false },
8
- { "feature": "windowMeasures", "protocolVersions": [3], "typescript": { "local": true, "publish": false }, "python": { "local": false, "publish": false }, "cloud": false },
9
- { "feature": "shiftMeasures", "protocolVersions": [3], "typescript": { "local": true, "publish": false }, "python": { "local": false, "publish": false }, "cloud": false },
10
- { "feature": "approxCountDistinct", "protocolVersions": [3], "typescript": { "local": true, "publish": false }, "python": { "local": false, "publish": false }, "cloud": false },
7
+ { "feature": "segments", "protocolVersions": [3], "typescript": { "local": true, "publish": false }, "python": { "local": true, "publish": false }, "cloud": false },
8
+ { "feature": "windowMeasures", "protocolVersions": [3], "typescript": { "local": true, "publish": false }, "python": { "local": true, "publish": false }, "cloud": false },
9
+ { "feature": "shiftMeasures", "protocolVersions": [3], "typescript": { "local": true, "publish": false }, "python": { "local": true, "publish": false }, "cloud": false },
10
+ { "feature": "approxCountDistinct", "protocolVersions": [3], "typescript": { "local": true, "publish": false }, "python": { "local": true, "publish": false }, "cloud": false },
11
11
  { "feature": "subDayGrains", "protocolVersions": [3], "typescript": { "local": true, "publish": false }, "python": { "local": true, "publish": false }, "cloud": false }
12
12
  ]
13
13
  }
@@ -1,5 +1,5 @@
1
1
  /** Dataset client orchestration: runtime defaults, caching, limits and target dispatch. */
2
- import type { MetricRef, GrainedMetricRef, MetricQuery, MetricQueryFor, MetricResult, MetricResultFor, DatasetQuery, DatasetQueryFor, DatasetQueryResult, DatasetQueryResultFor, ExecutionContext, AnyDatasetInstance, DatasetInstance } from './types.js';
2
+ import type { MetricRef, GrainedMetricRef, MetricQuery, MetricQueryFor, MetricResult, MetricResultFor, DatasetQuery, DatasetQueryFor, DatasetQueryResult, DatasetQueryResultFor, ExecutionContext, AnyDatasetInstance, DatasetInstance, DatasetRowFor, MetricRowFor, SemanticStreamResult, SemanticArrowStreamResult } from './types.js';
3
3
  import type { QueryBuilderFactoryInput } from './query-builder-protocol.js';
4
4
  import type { PlanNode, SemanticBackend } from './semantic-plan.js';
5
5
  import type { ValidationResult } from './validation.js';
@@ -44,6 +44,30 @@ export interface DatasetClient {
44
44
  execute<TDatasetName extends string, TMetricName extends string, TDataset extends TypedDataset<TDatasetName>, const TQuery extends MetricQueryFor<TDataset, TMetricName> = MetricQueryFor<TDataset, TMetricName>>(target: TypedMetricRef<TDatasetName, TMetricName, TDataset> | TypedGrainedMetricRef<TDatasetName, TMetricName, TDataset>, query?: TQuery, context?: ExecutionContext): Promise<MetricResultFor<TDataset, TMetricName, TQuery>>;
45
45
  /** Explicit row types opt into the legacy dynamic query contract. */
46
46
  execute<TRow = never, TTarget extends SemanticTarget = SemanticTarget>(target: [TRow] extends [never] ? never : TTarget, query?: SemanticQuery<TTarget>, context?: ExecutionContext): Promise<SemanticResult<TTarget, TRow>>;
47
+ /**
48
+ * Stream a semantic target's rows in batches, with the same validation,
49
+ * tenant scoping, `maxResultSize` ceiling and row types as `execute()`. Rows
50
+ * flow as ClickHouse sends them, so memory stays flat however many there
51
+ * are. Streams never use the result cache and report no pagination.
52
+ */
53
+ stream<TDataset extends TypedDataset, const TQuery extends DatasetQueryFor<TDataset> = DatasetQueryFor<TDataset>>(target: TDataset, query?: TQuery, context?: ExecutionContext): Promise<SemanticStreamResult<DatasetRowFor<TDataset, TQuery>>>;
54
+ stream<TDatasetName extends string, TMetricName extends string, TDataset extends TypedDataset<TDatasetName>, const TQuery extends MetricQueryFor<TDataset, TMetricName> = MetricQueryFor<TDataset, TMetricName>>(target: TypedMetricRef<TDatasetName, TMetricName, TDataset> | TypedGrainedMetricRef<TDatasetName, TMetricName, TDataset>, query?: TQuery, context?: ExecutionContext): Promise<SemanticStreamResult<MetricRowFor<TDataset, TMetricName, TQuery>>>;
55
+ /** Explicit row types opt into the legacy dynamic query contract. */
56
+ stream<TRow = never, TTarget extends SemanticTarget = SemanticTarget>(target: [TRow] extends [never] ? never : TTarget, query?: SemanticQuery<TTarget>, context?: ExecutionContext): Promise<SemanticStreamResult<TRow>>;
57
+ /**
58
+ * Stream a semantic target's result as Arrow IPC stream bytes, under the
59
+ * same validation, tenant scoping and `maxResultSize` ceiling as `execute()`.
60
+ * Columns keep their native database types. Decode with any Arrow reader:
61
+ *
62
+ * ```ts
63
+ * import { RecordBatchReader } from 'apache-arrow';
64
+ *
65
+ * const { data } = await analytics.streamArrow(orders, query);
66
+ * for await (const batch of await RecordBatchReader.from(data)) { ... }
67
+ * ```
68
+ */
69
+ streamArrow<TDataset extends TypedDataset>(target: TDataset, query?: DatasetQueryFor<TDataset>, context?: ExecutionContext): Promise<SemanticArrowStreamResult>;
70
+ streamArrow<TDatasetName extends string, TMetricName extends string, TDataset extends TypedDataset<TDatasetName>>(target: TypedMetricRef<TDatasetName, TMetricName, TDataset> | TypedGrainedMetricRef<TDatasetName, TMetricName, TDataset>, query?: MetricQueryFor<TDataset, TMetricName>, context?: ExecutionContext): Promise<SemanticArrowStreamResult>;
47
71
  /** Compile the actual dataset execution SQL, including ceilings and pagination overfetch.
48
72
  * SQL and parameters are trusted-only; describe()/JSON serialization omit values.
49
73
  * Frozen semantic backends and standalone metric handles are not supported.
@@ -88,6 +112,14 @@ export declare class DatasetClientImpl extends MetricQueryEngine implements Data
88
112
  execute<TDatasetName extends string, TMetricName extends string, TDataset extends DatasetInstance<any, any, any, TDatasetName>, const TQuery extends MetricQueryFor<TDataset, TMetricName> = MetricQueryFor<TDataset, TMetricName>>(target: MetricRef<TDatasetName, TMetricName, any, TDataset>, query?: TQuery, context?: ExecutionContext): Promise<MetricResultFor<TDataset, TMetricName, TQuery>>;
89
113
  execute<TDatasetName extends string, TMetricName extends string, TDataset extends DatasetInstance<any, any, any, TDatasetName>, const TQuery extends MetricQueryFor<TDataset, TMetricName> = MetricQueryFor<TDataset, TMetricName>>(target: GrainedMetricRef<TDatasetName, TMetricName, any, TDataset>, query?: TQuery, context?: ExecutionContext): Promise<MetricResultFor<TDataset, TMetricName, TQuery>>;
90
114
  execute<TDatasetName extends string, TMetricName extends string, TDataset extends TypedDataset<TDatasetName>, const TQuery extends MetricQueryFor<TDataset, TMetricName> = MetricQueryFor<TDataset, TMetricName>>(target: TypedMetricRef<TDatasetName, TMetricName, TDataset> | TypedGrainedMetricRef<TDatasetName, TMetricName, TDataset>, query?: TQuery, context?: ExecutionContext): Promise<MetricResultFor<TDataset, TMetricName, TQuery>>;
115
+ stream<TRow = Record<string, unknown>, TTarget extends SemanticTarget = SemanticTarget>(target: TTarget, query?: SemanticQuery<TTarget>, context?: ExecutionContext): Promise<SemanticStreamResult<TRow>>;
116
+ streamArrow<TTarget extends SemanticTarget>(target: TTarget, query?: SemanticQuery<TTarget>, context?: ExecutionContext): Promise<SemanticArrowStreamResult>;
117
+ /**
118
+ * Validates and bounds a query exactly as `execute()` does, then opens it as
119
+ * a stream. Validation runs before anything is sent, so an invalid query
120
+ * rejects rather than producing a stream that fails on its first read.
121
+ */
122
+ private openStream;
91
123
  compileDataset<TDataset extends TypedDataset>(target: TDataset, query?: DatasetQueryFor<TDataset>, context?: ExecutionContext): DatasetCompilation;
92
124
  toSQL<TTarget extends SemanticTarget>(target: TTarget, query?: SemanticQuery<TTarget>, context?: ExecutionContext): string;
93
125
  validate<TTarget extends SemanticTarget>(target: TTarget, query?: SemanticQuery<TTarget>, context?: ExecutionContext): ValidationResult;