@hypequery/deployment 0.15.1 → 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.
- package/dist/authorized-contract.d.ts.map +1 -1
- package/dist/authorized-contract.js +42 -5
- package/dist/semantic-calculation-validation.d.ts +6 -1
- package/dist/semantic-calculation-validation.d.ts.map +1 -1
- package/dist/semantic-calculation-validation.js +27 -1
- package/dist/semantic-operation-validation.d.ts.map +1 -1
- package/dist/semantic-operation-validation.js +23 -2
- package/dist/utils/relationship-measures.d.ts +23 -0
- package/dist/utils/relationship-measures.d.ts.map +1 -0
- package/dist/utils/relationship-measures.js +33 -0
- package/package.json +5 -5
|
@@ -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,
|
|
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, withDatasetAllowedFilters, } 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,7 +52,23 @@ 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
|
-
|
|
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
74
|
// Event operations (RFC 0027) are direct queries too.
|
|
@@ -59,6 +76,9 @@ function narrowToJoin(dataset, reachable, joinable) {
|
|
|
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);
|
|
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]));
|
|
62
82
|
return withDatasetAllowedFilters({
|
|
63
83
|
...withoutSegments,
|
|
64
84
|
dimensions: reachable
|
|
@@ -66,7 +86,14 @@ function narrowToJoin(dataset, reachable, joinable) {
|
|
|
66
86
|
? dimension
|
|
67
87
|
: concealDimension(dimension)))
|
|
68
88
|
: dataset.dimensions.filter(dimension => String(dimension.name) === timeField),
|
|
69
|
-
|
|
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
|
+
: [],
|
|
70
97
|
}, []);
|
|
71
98
|
}
|
|
72
99
|
/**
|
|
@@ -106,13 +133,23 @@ export function projectAuthorizedDeploymentContract(contract, principal, options
|
|
|
106
133
|
// Each published dataset as the principal sees it. Narrowing comes first,
|
|
107
134
|
// because a relationship it drops must not keep its target in the contract.
|
|
108
135
|
const projected = new Map();
|
|
136
|
+
// Target dataset -> its measures some published dataset selects through a join.
|
|
137
|
+
const traversable = new Map();
|
|
109
138
|
for (const dataset of contract.datasets) {
|
|
110
139
|
if (!isDeploymentEndpointAuthorized(dataset.endpoint, principal))
|
|
111
140
|
continue;
|
|
112
141
|
const visible = visibleIn(dataset);
|
|
113
142
|
if (visible === null)
|
|
114
143
|
continue;
|
|
115
|
-
|
|
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
|
+
}
|
|
116
153
|
}
|
|
117
154
|
const published = new Set(projected.keys());
|
|
118
155
|
const relationshipsOf = (name) => (projected.get(name)?.relationships ?? byName.get(name).relationships);
|
|
@@ -157,7 +194,7 @@ export function projectAuthorizedDeploymentContract(contract, principal, options
|
|
|
157
194
|
const datasets = contract.datasets
|
|
158
195
|
.filter(dataset => required.has(String(dataset.name)))
|
|
159
196
|
.map(dataset => (projected.get(String(dataset.name))
|
|
160
|
-
?? narrowToJoin(dataset, reachable.has(String(dataset.name)), joinable(dataset))));
|
|
197
|
+
?? narrowToJoin(dataset, reachable.has(String(dataset.name)), joinable(dataset), traversable.get(String(dataset.name)))));
|
|
161
198
|
return Object.freeze({
|
|
162
199
|
contract: validateProtocolDeploymentContractAtLowestVersion({ ...contract, datasets }),
|
|
163
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
|
-
*
|
|
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
|
|
1
|
+
{"version":3,"file":"semantic-calculation-validation.d.ts","sourceRoot":"","sources":["../src/semantic-calculation-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;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,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3D,sFAAsF;IACtF,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,gGAAgG;IAChG,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAaD,uEAAuE;AACvE,wBAAgB,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
|
-
*
|
|
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-operation-validation.d.ts","sourceRoot":"","sources":["../src/semantic-operation-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACV,mCAAmC,EACnC,kBAAkB,EAElB,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"semantic-operation-validation.d.ts","sourceRoot":"","sources":["../src/semantic-operation-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACV,mCAAmC,EACnC,kBAAkB,EAElB,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAa7B,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,uBAAuB;IACtC,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAwGD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,qBAAqB,EAChC,OAAO,EAAE,mCAAmC,EAC5C,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,mCAAmC,CAAC,EAClE,MAAM,EAAE,uBAAuB;AAC/B,mFAAmF;AACnF,OAAO,CAAC,EAAE,4BAA4B,GACrC,SAAS,0BAA0B,EAAE,CAgOvC;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,SAAS,kBAAkB,EAAE,EAC1C,OAAO,EAAE,mCAAmC,EAC5C,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,mCAAmC,CAAC,GACjE,SAAS,0BAA0B,EAAE,CAgBvC;AAED,oFAAoF;AACpF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,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"}
|
|
@@ -13,6 +13,7 @@ import { calculationConditionCount, calculationOutputNames, validateSemanticCalc
|
|
|
13
13
|
import { effectiveFilterOperators, protocolFilterLeaves } from './utils/filter-leaves.js';
|
|
14
14
|
import { timeSeriesRangeViolation } from './utils/time-series-range.js';
|
|
15
15
|
import { fieldBackingColumn, isTimeAxisVisible } from './utils/field-backing-column.js';
|
|
16
|
+
import { resolveRelationshipMeasure, selectableRelationshipMeasures } from './utils/relationship-measures.js';
|
|
16
17
|
/** Invocation 1 refuses `minute` and `hour` before they reach this check (RFC 0015). */
|
|
17
18
|
const ALL_GRAINS = ['minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'];
|
|
18
19
|
/**
|
|
@@ -68,6 +69,7 @@ function resolveDataset(dataset, datasets) {
|
|
|
68
69
|
filters,
|
|
69
70
|
impliedFilters,
|
|
70
71
|
measures: new Set(dataset.measures.map(measure => String(measure.name))),
|
|
72
|
+
relationshipMeasures: selectableRelationshipMeasures(dataset, datasets),
|
|
71
73
|
grains: new Set(dataset.timeField === undefined ? [] : ALL_GRAINS),
|
|
72
74
|
segments: new Set(datasetSegments(dataset).map(segment => String(segment.name))),
|
|
73
75
|
};
|
|
@@ -85,6 +87,9 @@ function narrowResolvedToVisible(allowed, visible) {
|
|
|
85
87
|
|| (allowed.impliedFilters.has(name) && visible.dimensions.has(name))))),
|
|
86
88
|
impliedFilters: new Set([...allowed.impliedFilters].filter(name => visible.dimensions.has(name))),
|
|
87
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)),
|
|
88
93
|
grains: visible.timeField ? allowed.grains : new Set(),
|
|
89
94
|
segments: visible.segments === undefined
|
|
90
95
|
? allowed.segments
|
|
@@ -132,9 +137,21 @@ visible) {
|
|
|
132
137
|
fail(`At most ${limits.maxMeasures} measures and calculation outputs may be selected together.`, '$.operation.calculations');
|
|
133
138
|
}
|
|
134
139
|
measures.forEach((name, index) => {
|
|
135
|
-
|
|
136
|
-
|
|
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;
|
|
137
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);
|
|
138
155
|
});
|
|
139
156
|
if (dimensions.length === 0 && measures.length === 0) {
|
|
140
157
|
fail('At least one dimension or measure must be selected.', '$.operation');
|
|
@@ -162,7 +179,9 @@ visible) {
|
|
|
162
179
|
for (const violation of validateSemanticCalculations(operation, dataset, {
|
|
163
180
|
measures: allowed.measures,
|
|
164
181
|
filters: allowed.filters,
|
|
182
|
+
groupable: allowed.groupable,
|
|
165
183
|
hasTimeField: allowed.grains.size > 0,
|
|
184
|
+
maxDimensions: limits.maxDimensions,
|
|
166
185
|
}))
|
|
167
186
|
fail(violation.message, violation.path);
|
|
168
187
|
filters.forEach(({ expression, path, negated }) => {
|
|
@@ -260,6 +279,8 @@ visible) {
|
|
|
260
279
|
const orderable = new Set([
|
|
261
280
|
...allowed.groupable,
|
|
262
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)),
|
|
263
284
|
...outputs,
|
|
264
285
|
...(operation.by === undefined ? [] : ['period']),
|
|
265
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypequery/deployment",
|
|
3
|
-
"version": "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
|
+
"@hypequery/protocol": "0.31.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^26.6.
|
|
32
|
+
"@types/node": "^26.6.11",
|
|
33
33
|
"typescript": "^6.0.3",
|
|
34
|
-
"vitest": "^5.1.
|
|
35
|
-
"@hypequery/datasets": "0.
|
|
34
|
+
"vitest": "^5.1.2",
|
|
35
|
+
"@hypequery/datasets": "0.36.0"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=20"
|