@hypequery/deployment 0.15.0 → 0.16.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.
@@ -1 +1 @@
1
- {"version":3,"file":"authorized-contract.d.ts","sourceRoot":"","sources":["../src/authorized-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,oCAAoC,EAEpC,sBAAsB,EAEvB,MAAM,qBAAqB,CAAC;AAM7B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAInE;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,oBAAoB,EAC5B,SAAS,EAAE,4BAA4B,GAAG,IAAI,GAC7C,OAAO,CAIT;AAED,mFAAmF;AACnF,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,sBAAsB,GAAG,SAAS,EAC5C,SAAS,EAAE,4BAA4B,GAAG,IAAI,GAC7C,OAAO,CAKT;AA8CD,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,oCAAoC,CAAC;IACxD;;;;;;;;;OASG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,qCAAqC;IACpD;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,oCAAoC,EAC9C,SAAS,EAAE,4BAA4B,GAAG,IAAI,EAC9C,OAAO,GAAE,qCAA0C,GAClD,8BAA8B,CA4EhC"}
1
+ {"version":3,"file":"authorized-contract.d.ts","sourceRoot":"","sources":["../src/authorized-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,oCAAoC,EAEpC,sBAAsB,EAIvB,MAAM,qBAAqB,CAAC;AAQ7B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAKnE;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,oBAAoB,EAC5B,SAAS,EAAE,4BAA4B,GAAG,IAAI,GAC7C,OAAO,CAIT;AAED,mFAAmF;AACnF,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,sBAAsB,GAAG,SAAS,EAC5C,SAAS,EAAE,4BAA4B,GAAG,IAAI,GAC7C,OAAO,CAKT;AA4ED,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,oCAAoC,CAAC;IACxD;;;;;;;;;OASG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,qCAAqC;IACpD;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,oCAAoC,EAC9C,SAAS,EAAE,4BAA4B,GAAG,IAAI,EAC9C,OAAO,GAAE,qCAA0C,GAClD,8BAA8B,CAuFhC"}
@@ -12,8 +12,9 @@
12
12
  * catalog projection or schema compilation therefore cannot advertise something
13
13
  * execution would refuse.
14
14
  */
15
- import { resolveProtocolVisibleDatasetFields, validateProtocolDeploymentContractAtLowestVersion, validateProtocolFieldVisibility, } from '@hypequery/protocol';
15
+ import { datasetAllowedFilters, resolveProtocolVisibleDatasetFields, validateProtocolDeploymentContractAtLowestVersion, validateProtocolFieldVisibility, withDatasetAllowedFilters, } from '@hypequery/protocol';
16
16
  import { missing } from './utils/required-access.js';
17
+ import { selectableRelationshipMeasures } from './utils/relationship-measures.js';
17
18
  import { concealDimension, narrowDatasetToVisible } from './utils/visibility-projection.js';
18
19
  /**
19
20
  * Whether a principal satisfies an access policy.
@@ -51,24 +52,49 @@ export function isDeploymentEndpointAuthorized(endpoint, principal) {
51
52
  * because a relationship names it and the contract would not validate without
52
53
  * it.
53
54
  */
54
- function narrowToJoin(dataset, reachable, joinable) {
55
+ /**
56
+ * A measure filter with each declared-filter name replaced by the field that
57
+ * filter reads, so it means the same once the declared filters are dropped.
58
+ */
59
+ function resolveFilterNames(expression, named) {
60
+ if (expression.kind === 'logical') {
61
+ return expression.operator === 'not'
62
+ ? { ...expression, operand: resolveFilterNames(expression.operand, named) }
63
+ : { ...expression, operands: expression.operands.map(operand => resolveFilterNames(operand, named)) };
64
+ }
65
+ if (expression.kind === 'comparison' && expression.left.kind === 'reference') {
66
+ const field = named.get(String(expression.left.name));
67
+ return field === undefined ? expression : { ...expression, left: { kind: 'reference', name: field } };
68
+ }
69
+ return expression;
70
+ }
71
+ function narrowToJoin(dataset, reachable, joinable, traversable = new Set()) {
55
72
  // `defaults` describes how to query the dataset directly, which is exactly
56
73
  // what this principal may not do. Segments select rows of a direct query too.
57
- const { defaults: _defaults, endpoint: _endpoint, ...rest } = dataset;
58
- const contract3 = 'allowedFilters' in dataset && dataset.allowedFilters !== undefined;
74
+ // Event operations (RFC 0027) are direct queries too.
75
+ const { defaults: _defaults, endpoint: _endpoint, events: _events, ...rest } = dataset;
59
76
  // Alternate time axes, like segments, only shape a direct query.
60
77
  const { segments: _segments, alternateTimeFields: _alternates, ...withoutSegments } = rest;
61
78
  const timeField = dataset.timeField === undefined ? undefined : String(dataset.timeField);
62
- return {
79
+ // The declared filters are dropped below, so a retained measure's fixed
80
+ // filter that names one is rewritten to the field it reads.
81
+ const named = new Map(datasetAllowedFilters(dataset).map(filter => [String(filter.name), filter.field]));
82
+ return withDatasetAllowedFilters({
63
83
  ...withoutSegments,
64
84
  dimensions: reachable
65
85
  ? dataset.dimensions.map(dimension => (joinable === undefined || joinable.has(String(dimension.name))
66
86
  ? dimension
67
87
  : concealDimension(dimension)))
68
88
  : dataset.dimensions.filter(dimension => String(dimension.name) === timeField),
69
- measures: [],
70
- ...(contract3 ? { allowedFilters: [] } : { filters: [] }),
71
- };
89
+ // RFC 0015: a base measure a published dataset may select through a join.
90
+ measures: reachable
91
+ ? dataset.measures
92
+ .filter(measure => traversable.has(String(measure.name)))
93
+ .map(measure => (measure.filters === undefined || measure.filters.length === 0
94
+ ? measure
95
+ : { ...measure, filters: measure.filters.map(filter => resolveFilterNames(filter, named)) }))
96
+ : [],
97
+ }, []);
72
98
  }
73
99
  /**
74
100
  * Projects the contract down to what `principal` may see.
@@ -107,13 +133,23 @@ export function projectAuthorizedDeploymentContract(contract, principal, options
107
133
  // Each published dataset as the principal sees it. Narrowing comes first,
108
134
  // because a relationship it drops must not keep its target in the contract.
109
135
  const projected = new Map();
136
+ // Target dataset -> its measures some published dataset selects through a join.
137
+ const traversable = new Map();
110
138
  for (const dataset of contract.datasets) {
111
139
  if (!isDeploymentEndpointAuthorized(dataset.endpoint, principal))
112
140
  continue;
113
141
  const visible = visibleIn(dataset);
114
142
  if (visible === null)
115
143
  continue;
116
- projected.set(String(dataset.name), visible ? narrowDatasetToVisible(dataset, visible) : dataset);
144
+ const narrowed = visible ? narrowDatasetToVisible(dataset, visible) : dataset;
145
+ projected.set(String(dataset.name), narrowed);
146
+ for (const qualified of selectableRelationshipMeasures(narrowed, byName)) {
147
+ if (visible && visible.relationshipMeasures?.has(qualified) !== true)
148
+ continue;
149
+ const [relationship, measure] = qualified.split('.');
150
+ const target = String(narrowed.relationships.find(entry => String(entry.name) === relationship).target);
151
+ traversable.set(target, (traversable.get(target) ?? new Set()).add(measure));
152
+ }
117
153
  }
118
154
  const published = new Set(projected.keys());
119
155
  const relationshipsOf = (name) => (projected.get(name)?.relationships ?? byName.get(name).relationships);
@@ -158,7 +194,7 @@ export function projectAuthorizedDeploymentContract(contract, principal, options
158
194
  const datasets = contract.datasets
159
195
  .filter(dataset => required.has(String(dataset.name)))
160
196
  .map(dataset => (projected.get(String(dataset.name))
161
- ?? narrowToJoin(dataset, reachable.has(String(dataset.name)), joinable(dataset))));
197
+ ?? narrowToJoin(dataset, reachable.has(String(dataset.name)), joinable(dataset), traversable.get(String(dataset.name)))));
162
198
  return Object.freeze({
163
199
  contract: validateProtocolDeploymentContractAtLowestVersion({ ...contract, datasets }),
164
200
  queryable: Object.freeze(datasets
@@ -6,7 +6,8 @@
6
6
  * dimensions. What remains needs the contract and the caller's visibility:
7
7
  * every published input is a measure the caller may see and of a kind the
8
8
  * calculation accepts, filter conditions use filters the caller may apply,
9
- * and the counts stay within the dataset's ceilings.
9
+ * a nested calculation's grain names dimensions the caller may group by
10
+ * (RFC 0032), and the counts stay within the dataset's ceilings.
10
11
  */
11
12
  import type { ProtocolDatasetQuery, ProtocolDeploymentDatasetAnyVersion } from '@hypequery/protocol';
12
13
  interface CalculationViolation {
@@ -17,7 +18,11 @@ interface CalculationViolation {
17
18
  export interface CalculationSurface {
18
19
  readonly measures: ReadonlySet<string>;
19
20
  readonly filters: ReadonlyMap<string, ReadonlySet<string>>;
21
+ /** Dimensions the caller may group by: what a nested calculation's grain may name. */
22
+ readonly groupable: ReadonlySet<string>;
20
23
  readonly hasTimeField: boolean;
24
+ /** Most dimensions one grouping may have; a nested inner stage groups by dimensions ∪ grain. */
25
+ readonly maxDimensions: number;
21
26
  }
22
27
  /** Every output column a query's calculations add, in output order. */
23
28
  export declare function calculationOutputNames(operation: ProtocolDatasetQuery): string[];
@@ -1 +1 @@
1
- {"version":3,"file":"semantic-calculation-validation.d.ts","sourceRoot":"","sources":["../src/semantic-calculation-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,mCAAmC,EAEpC,MAAM,qBAAqB,CAAC;AAG7B,UAAU,oBAAoB;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,mEAAmE;AACnE,MAAM,WAAW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B,sBAAsB,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAMhF;AAED,qFAAqF;AACrF,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,CAEjF;AAED,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,oBAAoB,EAC/B,OAAO,EAAE,mCAAmC,EAC5C,OAAO,EAAE,kBAAkB,GAC1B,SAAS,oBAAoB,EAAE,CAuGjC"}
@@ -6,7 +6,8 @@
6
6
  * dimensions. What remains needs the contract and the caller's visibility:
7
7
  * every published input is a measure the caller may see and of a kind the
8
8
  * calculation accepts, filter conditions use filters the caller may apply,
9
- * and the counts stay within the dataset's ceilings.
9
+ * a nested calculation's grain names dimensions the caller may group by
10
+ * (RFC 0032), and the counts stay within the dataset's ceilings.
10
11
  */
11
12
  import { comparisonField } from './utils/semantic-comparison-field.js';
12
13
  const UNFILTERABLE = new Set(['argMax', 'argMin', 'merge']);
@@ -41,6 +42,15 @@ export function validateSemanticCalculations(operation, dataset, surface) {
41
42
  return measure;
42
43
  };
43
44
  const timed = (measure) => measure?.kind === 'shift' || measure?.kind === 'window';
45
+ /** A time measure, or a derived one computed from any. */
46
+ const dependsOnTime = (measure, seen = new Set()) => {
47
+ if (measure === undefined || seen.has(measure.name))
48
+ return false;
49
+ if (timed(measure))
50
+ return true;
51
+ const next = new Set([...seen, measure.name]);
52
+ return (measure.uses ?? []).some(use => dependsOnTime(measures.get(String(use.measure)), next));
53
+ };
44
54
  (operation.calculations ?? []).forEach((entry, index) => {
45
55
  const path = `$.operation.calculations[${index}]`;
46
56
  if ('filter' in entry) {
@@ -88,6 +98,22 @@ export function validateSemanticCalculations(operation, dataset, surface) {
88
98
  fail(`"${String(name)}" is already a ${measure.kind} measure.`, `${path}.compare.measures[${at}]`);
89
99
  });
90
100
  }
101
+ else if ('nested' in entry) {
102
+ // RFC 0032: the inner stage groups by dimensions the query may not select.
103
+ const measure = published(String(entry.nested.measure), `${path}.nested.measure`);
104
+ if (dependsOnTime(measure)) {
105
+ fail(`A nested calculation cannot read "${measure.name}", which depends on a window or shift measure.`, `${path}.nested.measure`);
106
+ }
107
+ entry.nested.grain.forEach((name, at) => {
108
+ if (!surface.groupable.has(String(name))) {
109
+ fail(`Unknown or non-groupable dimension "${String(name)}".`, `${path}.nested.grain[${at}]`);
110
+ }
111
+ });
112
+ const grouping = new Set([...(operation.dimensions ?? []), ...entry.nested.grain].map(String));
113
+ if (grouping.size > surface.maxDimensions) {
114
+ fail(`A nested calculation groups by at most ${surface.maxDimensions} dimensions, its grain included.`, `${path}.nested.grain`);
115
+ }
116
+ }
91
117
  if (('shift' in entry || 'window' in entry || 'compare' in entry) && !surface.hasTimeField) {
92
118
  fail('This dataset has no time field, so time calculations do not apply.', path);
93
119
  }
@@ -1 +1 @@
1
- {"version":3,"file":"semantic-filter-capabilities.d.ts","sourceRoot":"","sources":["../src/semantic-filter-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,mCAAmC,EACpC,MAAM,qBAAqB,CAAC;AAE7B,mFAAmF;AACnF,eAAO,MAAM,iCAAiC,EAAE,WAAW,CAAC,MAAM,CAEhE,CAAC;AAEH,MAAM,WAAW,0BAA0B;IACzC,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAC3D,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CAC/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,mCAAmC,GAC3C,0BAA0B,CA2B5B"}
1
+ {"version":3,"file":"semantic-filter-capabilities.d.ts","sourceRoot":"","sources":["../src/semantic-filter-capabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,mCAAmC,EAAE,MAAM,qBAAqB,CAAC;AAEtG,mFAAmF;AACnF,eAAO,MAAM,iCAAiC,EAAE,WAAW,CAAC,MAAM,CAEhE,CAAC;AAEH,MAAM,WAAW,0BAA0B;IACzC,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAC3D,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CAC/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,mCAAmC,GAC3C,0BAA0B,CAyB5B"}
@@ -1,3 +1,4 @@
1
+ import { datasetAllowedFilters } from '@hypequery/protocol';
1
2
  /** The dataset layer's default caller-filter operators; null checks are opt-in. */
2
3
  export const DEFAULT_SEMANTIC_FILTER_OPERATORS = new Set([
3
4
  'eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'in', 'notIn', 'between', 'like',
@@ -14,9 +15,7 @@ export const DEFAULT_SEMANTIC_FILTER_OPERATORS = new Set([
14
15
  * - otherwise a filterable dimension gets the value-operator defaults.
15
16
  */
16
17
  export function protocolFilterCapabilities(dataset) {
17
- const allowList = 'allowedFilters' in dataset && dataset.allowedFilters !== undefined
18
- ? dataset.allowedFilters
19
- : dataset.filters;
18
+ const allowList = datasetAllowedFilters(dataset);
20
19
  const named = new Map(allowList.map(filter => [String(filter.name), filter]));
21
20
  const dimensions = new Map();
22
21
  for (const dimension of dataset.dimensions) {
@@ -1 +1 @@
1
- {"version":3,"file":"semantic-operation-validation.d.ts","sourceRoot":"","sources":["../src/semantic-operation-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,mCAAmC,EAEnC,kBAAkB,EAElB,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAY7B,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM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AAC,MAAM,CAAC,CAAC;IACxC,wCAAwC;IACxC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CAC5D;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,mCAAmC,EAC5C,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,mCAAmC,CAAC,EAClE,OAAO,CAAC,EAAE,4BAA4B,GACrC,qBAAqB,CAIvB;AAED,0FAA0F;AAC1F,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,kBAAkB,GAC7B;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAE5C"}
@@ -6,12 +6,14 @@
6
6
  * loading the authoring package. A gateway must be able to reject a bad
7
7
  * invocation without any of the deploying application's code.
8
8
  */
9
+ import { datasetSegments, datasetTimeAxes } from '@hypequery/protocol';
9
10
  import { protocolFilterCapabilities } from './semantic-filter-capabilities.js';
10
11
  import { comparisonField } from './utils/semantic-comparison-field.js';
11
12
  import { calculationConditionCount, calculationOutputNames, validateSemanticCalculations, } from './semantic-calculation-validation.js';
12
13
  import { effectiveFilterOperators, protocolFilterLeaves } from './utils/filter-leaves.js';
13
14
  import { timeSeriesRangeViolation } from './utils/time-series-range.js';
14
15
  import { fieldBackingColumn, isTimeAxisVisible } from './utils/field-backing-column.js';
16
+ import { resolveRelationshipMeasure, selectableRelationshipMeasures } from './utils/relationship-measures.js';
15
17
  /** Invocation 1 refuses `minute` and `hour` before they reach this check (RFC 0015). */
16
18
  const ALL_GRAINS = ['minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'];
17
19
  /**
@@ -67,8 +69,9 @@ function resolveDataset(dataset, datasets) {
67
69
  filters,
68
70
  impliedFilters,
69
71
  measures: new Set(dataset.measures.map(measure => String(measure.name))),
72
+ relationshipMeasures: selectableRelationshipMeasures(dataset, datasets),
70
73
  grains: new Set(dataset.timeField === undefined ? [] : ALL_GRAINS),
71
- segments: new Set((dataset.segments ?? []).map(segment => String(segment.name))),
74
+ segments: new Set(datasetSegments(dataset).map(segment => String(segment.name))),
72
75
  };
73
76
  }
74
77
  /**
@@ -84,6 +87,9 @@ function narrowResolvedToVisible(allowed, visible) {
84
87
  || (allowed.impliedFilters.has(name) && visible.dimensions.has(name))))),
85
88
  impliedFilters: new Set([...allowed.impliedFilters].filter(name => visible.dimensions.has(name))),
86
89
  measures: new Set([...allowed.measures].filter(name => visible.measures.has(name))),
90
+ // A record without the field predates relationship measures: none visible.
91
+ relationshipMeasures: new Set([...allowed.relationshipMeasures]
92
+ .filter(name => visible.relationshipMeasures?.has(name) === true)),
87
93
  grains: visible.timeField ? allowed.grains : new Set(),
88
94
  segments: visible.segments === undefined
89
95
  ? allowed.segments
@@ -131,9 +137,21 @@ visible) {
131
137
  fail(`At most ${limits.maxMeasures} measures and calculation outputs may be selected together.`, '$.operation.calculations');
132
138
  }
133
139
  measures.forEach((name, index) => {
134
- if (!allowed.measures.has(String(name))) {
135
- fail(`Unknown measure "${String(name)}".`, `$.operation.measures[${index}]`);
140
+ const path = `$.operation.measures[${index}]`;
141
+ if (!String(name).includes('.')) {
142
+ if (!allowed.measures.has(String(name)))
143
+ fail(`Unknown measure "${String(name)}".`, path);
144
+ return;
136
145
  }
146
+ // RFC 0015: a one-hop relationship measure, where the planner can run it.
147
+ if (allowed.relationshipMeasures.has(String(name)))
148
+ return;
149
+ const resolution = resolveRelationshipMeasure(dataset, datasets, String(name));
150
+ // The rule's reason names the relationship kind and aggregation. A caller
151
+ // who may not see the measure gets the unknown-measure message instead, so
152
+ // a refusal never confirms that a hidden one exists.
153
+ const seen = visible === undefined || visible.relationshipMeasures?.has(String(name)) === true;
154
+ fail(!resolution.ok && seen ? resolution.reason : `Unknown measure "${String(name)}".`, path);
137
155
  });
138
156
  if (dimensions.length === 0 && measures.length === 0) {
139
157
  fail('At least one dimension or measure must be selected.', '$.operation');
@@ -161,7 +179,9 @@ visible) {
161
179
  for (const violation of validateSemanticCalculations(operation, dataset, {
162
180
  measures: allowed.measures,
163
181
  filters: allowed.filters,
182
+ groupable: allowed.groupable,
164
183
  hasTimeField: allowed.grains.size > 0,
184
+ maxDimensions: limits.maxDimensions,
165
185
  }))
166
186
  fail(violation.message, violation.path);
167
187
  filters.forEach(({ expression, path, negated }) => {
@@ -197,14 +217,11 @@ visible) {
197
217
  };
198
218
  // RFC 0029: the time axes a caller may use, in contract order. A hidden
199
219
  // alternate reads exactly like an undeclared one.
200
- const axes = dataset.timeField === undefined || allowed.grains.size === 0
220
+ const axes = allowed.grains.size === 0
201
221
  ? []
202
- : [
203
- String(dataset.timeField),
204
- ...(dataset.alternateTimeFields ?? [])
205
- .map(String)
206
- .filter(name => visible === undefined || isTimeAxisVisible(dataset, name, visible.dimensions)),
207
- ];
222
+ : datasetTimeAxes(dataset)
223
+ .map(String)
224
+ .filter((name, index) => index === 0 || visible === undefined || isTimeAxisVisible(dataset, name, visible.dimensions));
208
225
  let timeAxis = axes[0];
209
226
  if (operation.timeKey !== undefined) {
210
227
  if (axes.includes(String(operation.timeKey))) {
@@ -262,6 +279,8 @@ visible) {
262
279
  const orderable = new Set([
263
280
  ...allowed.groupable,
264
281
  ...allowed.measures,
282
+ // The executor orders by a joined measure only when the query selects it.
283
+ ...measures.map(String).filter(name => allowed.relationshipMeasures.has(name)),
265
284
  ...outputs,
266
285
  ...(operation.by === undefined ? [] : ['period']),
267
286
  ]);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * RFC 0015 relationship measures as the data plane resolves them. The rule
3
+ * itself lives in `@hypequery/protocol`, so this gateway, the agent catalog
4
+ * and any other consumer accept exactly the same names.
5
+ */
6
+ import type { ProtocolDeploymentDatasetAnyVersion } from '@hypequery/protocol';
7
+ /** A selectable relationship measure, or why it is not one. */
8
+ export type RelationshipMeasureResolution = {
9
+ readonly ok: true;
10
+ readonly relationship: string;
11
+ readonly measure: string;
12
+ } | {
13
+ readonly ok: false;
14
+ readonly reason: string;
15
+ };
16
+ /** Every `<relationship>.<measure>` a dataset offers. */
17
+ export declare function selectableRelationshipMeasures(dataset: ProtocolDeploymentDatasetAnyVersion, datasets: ReadonlyMap<string, ProtocolDeploymentDatasetAnyVersion>): ReadonlySet<string>;
18
+ /**
19
+ * Resolves a qualified measure name against the contract, with the reason it
20
+ * is refused. An unknown relationship or target measure reads as unknown.
21
+ */
22
+ export declare function resolveRelationshipMeasure(dataset: ProtocolDeploymentDatasetAnyVersion, datasets: ReadonlyMap<string, ProtocolDeploymentDatasetAnyVersion>, qualified: string): RelationshipMeasureResolution;
23
+ //# sourceMappingURL=relationship-measures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relationship-measures.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-measures.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,qBAAqB,CAAC;AAE/E,+DAA+D;AAC/D,MAAM,MAAM,6BAA6B,GACrC;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC9E;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD,yDAAyD;AACzD,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,mCAAmC,EAC5C,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,mCAAmC,CAAC,GACjE,WAAW,CAAC,MAAM,CAAC,CAErB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,mCAAmC,EAC5C,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,mCAAmC,CAAC,EAClE,SAAS,EAAE,MAAM,GAChB,6BAA6B,CAiB/B"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * RFC 0015 relationship measures as the data plane resolves them. The rule
3
+ * itself lives in `@hypequery/protocol`, so this gateway, the agent catalog
4
+ * and any other consumer accept exactly the same names.
5
+ */
6
+ import { datasetRelationshipMeasures, relationshipMeasureRefusal } from '@hypequery/protocol';
7
+ /** Every `<relationship>.<measure>` a dataset offers. */
8
+ export function selectableRelationshipMeasures(dataset, datasets) {
9
+ return new Set(datasetRelationshipMeasures(dataset, datasets).map(entry => entry.name));
10
+ }
11
+ /**
12
+ * Resolves a qualified measure name against the contract, with the reason it
13
+ * is refused. An unknown relationship or target measure reads as unknown.
14
+ */
15
+ export function resolveRelationshipMeasure(dataset, datasets, qualified) {
16
+ const parts = qualified.split('.');
17
+ if (parts.length !== 2)
18
+ return { ok: false, reason: `Unknown measure "${qualified}".` };
19
+ const [relationshipName, measureName] = parts;
20
+ const relationship = dataset.relationships.find(entry => String(entry.name) === relationshipName);
21
+ const target = relationship === undefined ? undefined : datasets.get(String(relationship.target));
22
+ const measure = target?.measures
23
+ ?.find(entry => String(entry.name) === measureName);
24
+ if (relationship === undefined || target === undefined || measure === undefined) {
25
+ return { ok: false, reason: `Unknown measure "${qualified}".` };
26
+ }
27
+ const refusal = relationshipMeasureRefusal(relationship, target, measure)
28
+ // Every to-one relationship is queryable in a valid contract; hasMany never is.
29
+ ?? (relationship.queryable ? undefined : `Unknown measure "${qualified}".`);
30
+ return refusal === undefined
31
+ ? { ok: true, relationship: relationshipName, measure: measureName }
32
+ : { ok: false, reason: refusal };
33
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"visibility-projection.d.ts","sourceRoot":"","sources":["../../src/utils/visibility-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,mCAAmC,EAEnC,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAG7B,KAAK,SAAS,GAAG,yBAAyB,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAQhE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,SAAS,mCAAmC,EACzF,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,4BAA4B,GACpC,QAAQ,CAwCV"}
1
+ {"version":3,"file":"visibility-projection.d.ts","sourceRoot":"","sources":["../../src/utils/visibility-projection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,yBAAyB,EACzB,mCAAmC,EAEnC,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAG7B,KAAK,SAAS,GAAG,yBAAyB,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAQhE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,SAAS,mCAAmC,EACzF,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,4BAA4B,GACpC,QAAQ,CA4CV"}
@@ -1,3 +1,4 @@
1
+ import { datasetAllowedFilters, withDatasetAllowedFilters } from '@hypequery/protocol';
1
2
  import { isTimeAxisVisible } from './field-backing-column.js';
2
3
  /**
3
4
  * A dimension the principal may neither group nor filter by, with its label,
@@ -26,7 +27,7 @@ export function concealDimension(dimension) {
26
27
  * the defaults that depend on it go. The result is still a valid dataset.
27
28
  */
28
29
  export function narrowDatasetToVisible(dataset, visible) {
29
- const { defaults, timeField, ...rest } = dataset;
30
+ const { defaults, timeField, events, ...rest } = dataset;
30
31
  const { alternateTimeFields, ...withoutAlternates } = rest;
31
32
  // RFC 0029: an alternate axis shows only beside a visible default axis, and
32
33
  // only when a dimension naming it or reading its column is visible, so a
@@ -35,30 +36,34 @@ export function narrowDatasetToVisible(dataset, visible) {
35
36
  ? alternateTimeFields?.filter(name => isTimeAxisVisible(dataset, String(name), visible.dimensions))
36
37
  : undefined;
37
38
  const defaultDimensions = defaults?.dimensions?.filter(name => visible.dimensions.has(String(name)));
39
+ // RFC 0027: event operations need the entity and the event time. Without
40
+ // either, the dataset stays discoverable without them; a hidden event
41
+ // dimension only narrows the declaration, as the field is optional.
42
+ const visibleEvents = events === undefined || !visible.timeField || !visible.dimensions.has(String(events.entity))
43
+ ? undefined
44
+ : events.event === undefined || visible.dimensions.has(String(events.event))
45
+ ? events
46
+ : { entity: events.entity };
38
47
  const narrowedDefaults = {
39
48
  ...(defaultDimensions === undefined || defaultDimensions.length === 0
40
49
  ? {}
41
50
  : { dimensions: defaultDimensions }),
42
51
  ...(defaults?.timeGrain === undefined || !visible.timeField ? {} : { timeGrain: defaults.timeGrain }),
43
52
  };
44
- return {
53
+ return withDatasetAllowedFilters({
45
54
  ...withoutAlternates,
46
55
  ...(visible.timeField && timeField !== undefined ? { timeField } : {}),
56
+ ...(visibleEvents === undefined ? {} : { events: visibleEvents }),
47
57
  ...(visibleAlternates === undefined || visibleAlternates.length === 0 ? {} : { alternateTimeFields: visibleAlternates }),
48
58
  // An empty `defaults` object is not a valid contract value.
49
59
  ...(Object.keys(narrowedDefaults).length === 0 ? {} : { defaults: narrowedDefaults }),
50
60
  dimensions: dataset.dimensions.map(dimension => (visible.dimensions.has(String(dimension.name)) ? dimension : concealDimension(dimension))),
51
61
  measures: dataset.measures
52
62
  .filter(measure => visible.measures.has(String(measure.name))),
53
- // Contract 3 renames the allow-list `allowedFilters` (RFC 0015).
54
- ...('allowedFilters' in dataset && dataset.allowedFilters !== undefined
55
- ? { allowedFilters: dataset.allowedFilters.filter(filter => visible.filters.has(String(filter.name))) }
56
- : { filters: dataset.filters
57
- .filter(filter => visible.filters.has(String(filter.name))) }),
58
63
  ...(dataset.segments === undefined ? {} : {
59
64
  segments: dataset.segments
60
65
  .filter(segment => visible.segments?.has(String(segment.name)) ?? true),
61
66
  }),
62
67
  relationships: dataset.relationships.filter(relationship => (visible.relationships.has(String(relationship.name)))),
63
- };
68
+ }, datasetAllowedFilters(dataset).filter(filter => visible.filters.has(String(filter.name))));
64
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypequery/deployment",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Verified deployment intake, activation, and semantic invocation for Hypequery analytics",
5
5
  "keywords": [
6
6
  "hypequery",
@@ -26,13 +26,13 @@
26
26
  "README.md"
27
27
  ],
28
28
  "dependencies": {
29
- "@hypequery/protocol": "0.29.0"
29
+ "@hypequery/protocol": "0.31.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/node": "^26.6.6",
32
+ "@types/node": "^26.6.11",
33
33
  "typescript": "^6.0.3",
34
- "vitest": "^5.1.0",
35
- "@hypequery/datasets": "0.34.0"
34
+ "vitest": "^5.1.2",
35
+ "@hypequery/datasets": "0.36.0"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=20"