@hypequery/deployment 0.13.0 → 0.15.1
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 +5 -4
- package/dist/authorized-contract.d.ts.map +1 -1
- package/dist/authorized-contract.js +10 -8
- package/dist/bundle.d.ts +2 -2
- package/dist/bundle.d.ts.map +1 -1
- package/dist/bundle.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/semantic-calculation-validation.d.ts +28 -0
- package/dist/semantic-calculation-validation.d.ts.map +1 -0
- package/dist/semantic-calculation-validation.js +110 -0
- package/dist/semantic-data-plane.d.ts +25 -8
- package/dist/semantic-data-plane.d.ts.map +1 -1
- package/dist/semantic-data-plane.js +44 -18
- package/dist/semantic-event-operation-validation.d.ts +25 -0
- package/dist/semantic-event-operation-validation.d.ts.map +1 -0
- package/dist/semantic-event-operation-validation.js +203 -0
- package/dist/semantic-filter-capabilities.d.ts +22 -0
- package/dist/semantic-filter-capabilities.d.ts.map +1 -0
- package/dist/semantic-filter-capabilities.js +38 -0
- package/dist/semantic-invocation-errors.d.ts +4 -3
- package/dist/semantic-invocation-errors.d.ts.map +1 -1
- package/dist/semantic-invocation-errors.js +5 -3
- package/dist/semantic-operation-validation.d.ts +19 -3
- package/dist/semantic-operation-validation.d.ts.map +1 -1
- package/dist/semantic-operation-validation.js +145 -34
- package/dist/utils/event-time-range.d.ts +36 -0
- package/dist/utils/event-time-range.d.ts.map +1 -0
- package/dist/utils/event-time-range.js +116 -0
- package/dist/utils/field-backing-column.d.ts +17 -0
- package/dist/utils/field-backing-column.d.ts.map +1 -0
- package/dist/utils/field-backing-column.js +24 -0
- package/dist/utils/filter-leaves.d.ts +22 -0
- package/dist/utils/filter-leaves.d.ts.map +1 -0
- package/dist/utils/filter-leaves.js +43 -0
- package/dist/utils/semantic-comparison-field.d.ts +17 -0
- package/dist/utils/semantic-comparison-field.d.ts.map +1 -0
- package/dist/utils/semantic-comparison-field.js +19 -0
- package/dist/utils/time-series-range.d.ts +17 -0
- package/dist/utils/time-series-range.d.ts.map +1 -0
- package/dist/utils/time-series-range.js +32 -0
- package/dist/utils/visibility-projection.d.ts +2 -2
- package/dist/utils/visibility-projection.d.ts.map +1 -1
- package/dist/utils/visibility-projection.js +29 -6
- package/dist/utils/visible-measure-selection.d.ts +2 -2
- package/dist/utils/visible-measure-selection.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ProtocolExpression } from '@hypequery/protocol';
|
|
2
|
+
/** A bounded time range read from an RFC 0027 operation's filters, as instants. */
|
|
3
|
+
export interface EventTimeRange {
|
|
4
|
+
readonly startMs: number;
|
|
5
|
+
readonly endMs: number;
|
|
6
|
+
/** The query zone the scan reads offset-free bounds and buckets in. */
|
|
7
|
+
readonly timezone: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* An ISO date or timestamp as an instant. A bound with `Z` or an offset is
|
|
11
|
+
* already one; an offset-free bound is a wall clock in `timezone`, exactly as
|
|
12
|
+
* the scan compares it (RFC 0025).
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseEventTimeBound(value: unknown, timezone?: string): number | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Exactly one bounded range on the time field: one `between`, or one
|
|
17
|
+
* `gt`/`gte` with one `lt`/`lte`, with ISO bounds. The rule window measures
|
|
18
|
+
* already follow, so a caller learns one shape.
|
|
19
|
+
*/
|
|
20
|
+
export declare function eventTimeRange(filters: readonly ProtocolExpression[], isTimeFilter: (name: string) => boolean, timezone?: string): EventTimeRange | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* An upper bound on the buckets a range spans at a grain in its query zone.
|
|
23
|
+
* Days and weeks round the span up and add one for a partial first bucket;
|
|
24
|
+
* a DST day is at most an hour longer, which the rounding absorbs. Months
|
|
25
|
+
* are counted from the local calendar months the two bounds fall in.
|
|
26
|
+
*/
|
|
27
|
+
export declare function estimateEventBuckets(range: EventTimeRange, grain: 'day' | 'week' | 'month'): number;
|
|
28
|
+
/**
|
|
29
|
+
* The most buckets a span of `days` can touch wherever it is placed: a
|
|
30
|
+
* relative range resolves against a clock the data plane doesn't read. A
|
|
31
|
+
* month is at least 28 days, so a span meets at most one more month than
|
|
32
|
+
* fits in it; days and weeks are as for a fixed range.
|
|
33
|
+
*/
|
|
34
|
+
export declare function estimatePlacementFreeBuckets(days: number, grain: 'day' | 'week' | 'month'): number;
|
|
35
|
+
export declare function eventRangeDays(range: EventTimeRange): number;
|
|
36
|
+
//# sourceMappingURL=event-time-range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-time-range.d.ts","sourceRoot":"","sources":["../../src/utils/event-time-range.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,mFAAmF;AACnF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAmBD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,SAAQ,GAAG,MAAM,GAAG,SAAS,CAgBxF;AAcD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,SAAS,kBAAkB,EAAE,EACtC,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,EACvC,QAAQ,SAAQ,GACf,cAAc,GAAG,SAAS,CAsB5B;AAID;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAOnG;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAKlG;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAE5D"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const ISO_BOUND = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,9})?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
2
|
+
function zoneParts(at, timezone) {
|
|
3
|
+
const parts = new Intl.DateTimeFormat('en-GB', {
|
|
4
|
+
timeZone: timezone, hourCycle: 'h23', year: 'numeric', month: '2-digit', day: '2-digit',
|
|
5
|
+
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
6
|
+
}).formatToParts(new Date(at));
|
|
7
|
+
return Object.fromEntries(parts.filter(part => part.type !== 'literal').map(part => [part.type, Number(part.value)]));
|
|
8
|
+
}
|
|
9
|
+
/** How far `timezone`'s wall clock is ahead of UTC at instant `at`. */
|
|
10
|
+
function zoneOffset(at, timezone) {
|
|
11
|
+
const parts = zoneParts(at, timezone);
|
|
12
|
+
const wall = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second);
|
|
13
|
+
return wall - Math.floor(at / 1000) * 1000;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* An ISO date or timestamp as an instant. A bound with `Z` or an offset is
|
|
17
|
+
* already one; an offset-free bound is a wall clock in `timezone`, exactly as
|
|
18
|
+
* the scan compares it (RFC 0025).
|
|
19
|
+
*/
|
|
20
|
+
export function parseEventTimeBound(value, timezone = 'UTC') {
|
|
21
|
+
if (typeof value !== 'string')
|
|
22
|
+
return undefined;
|
|
23
|
+
const match = ISO_BOUND.exec(value);
|
|
24
|
+
if (!match)
|
|
25
|
+
return undefined;
|
|
26
|
+
const [, year, month, day, hour = '00', minute = '00', second = '00', offset] = match;
|
|
27
|
+
const date = new Date(`${year}-${month}-${day}T00:00:00Z`);
|
|
28
|
+
if (!Number.isFinite(date.getTime()) || date.toISOString().slice(0, 10) !== `${year}-${month}-${day}`) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (Number(hour) > 23 || Number(minute) > 59 || Number(second) > 59)
|
|
32
|
+
return undefined;
|
|
33
|
+
const clock = `${year}-${month}-${day}T${hour}:${minute}:${second}`;
|
|
34
|
+
const wall = Date.parse(`${clock}${offset ?? 'Z'}`);
|
|
35
|
+
if (!Number.isFinite(wall))
|
|
36
|
+
return undefined;
|
|
37
|
+
if (offset !== undefined || timezone === 'UTC')
|
|
38
|
+
return wall;
|
|
39
|
+
// Two passes settle a wall clock next to a DST change.
|
|
40
|
+
return wall - zoneOffset(wall - zoneOffset(wall, timezone), timezone);
|
|
41
|
+
}
|
|
42
|
+
function literalValues(expression) {
|
|
43
|
+
if (expression.kind !== 'comparison' || !('right' in expression) || expression.right.kind !== 'literal') {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const value = expression.right.value;
|
|
47
|
+
if (typeof value === 'object' && value !== null && '$hypequery' in value) {
|
|
48
|
+
const tag = value.$hypequery;
|
|
49
|
+
return tag.values;
|
|
50
|
+
}
|
|
51
|
+
return [value];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Exactly one bounded range on the time field: one `between`, or one
|
|
55
|
+
* `gt`/`gte` with one `lt`/`lte`, with ISO bounds. The rule window measures
|
|
56
|
+
* already follow, so a caller learns one shape.
|
|
57
|
+
*/
|
|
58
|
+
export function eventTimeRange(filters, isTimeFilter, timezone = 'UTC') {
|
|
59
|
+
const time = filters.filter(filter => (filter.kind === 'comparison' && filter.left.kind === 'reference' && isTimeFilter(String(filter.left.name))));
|
|
60
|
+
let lower;
|
|
61
|
+
let upper;
|
|
62
|
+
if (time.length === 1 && time[0].kind === 'comparison' && time[0].operator === 'between') {
|
|
63
|
+
[lower, upper] = literalValues(time[0]) ?? [];
|
|
64
|
+
}
|
|
65
|
+
else if (time.length === 2) {
|
|
66
|
+
const operator = (filter) => (filter.kind === 'comparison' ? filter.operator : '');
|
|
67
|
+
const start = time.find(filter => operator(filter) === 'gt' || operator(filter) === 'gte');
|
|
68
|
+
const end = time.find(filter => operator(filter) === 'lt' || operator(filter) === 'lte');
|
|
69
|
+
if (!start || !end)
|
|
70
|
+
return undefined;
|
|
71
|
+
lower = literalValues(start)?.[0];
|
|
72
|
+
upper = literalValues(end)?.[0];
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const startMs = parseEventTimeBound(lower, timezone);
|
|
78
|
+
const endMs = parseEventTimeBound(upper, timezone);
|
|
79
|
+
if (startMs === undefined || endMs === undefined || endMs < startMs)
|
|
80
|
+
return undefined;
|
|
81
|
+
return { startMs, endMs, timezone };
|
|
82
|
+
}
|
|
83
|
+
const DAY_MS = 86_400_000;
|
|
84
|
+
/**
|
|
85
|
+
* An upper bound on the buckets a range spans at a grain in its query zone.
|
|
86
|
+
* Days and weeks round the span up and add one for a partial first bucket;
|
|
87
|
+
* a DST day is at most an hour longer, which the rounding absorbs. Months
|
|
88
|
+
* are counted from the local calendar months the two bounds fall in.
|
|
89
|
+
*/
|
|
90
|
+
export function estimateEventBuckets(range, grain) {
|
|
91
|
+
const spanDays = Math.ceil((range.endMs - range.startMs) / DAY_MS);
|
|
92
|
+
if (grain === 'day')
|
|
93
|
+
return spanDays + 1;
|
|
94
|
+
if (grain === 'week')
|
|
95
|
+
return Math.ceil(spanDays / 7) + 1;
|
|
96
|
+
const start = zoneParts(range.startMs, range.timezone);
|
|
97
|
+
const end = zoneParts(range.endMs, range.timezone);
|
|
98
|
+
return (end.year - start.year) * 12 + end.month - start.month + 1;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The most buckets a span of `days` can touch wherever it is placed: a
|
|
102
|
+
* relative range resolves against a clock the data plane doesn't read. A
|
|
103
|
+
* month is at least 28 days, so a span meets at most one more month than
|
|
104
|
+
* fits in it; days and weeks are as for a fixed range.
|
|
105
|
+
*/
|
|
106
|
+
export function estimatePlacementFreeBuckets(days, grain) {
|
|
107
|
+
const span = Math.ceil(days);
|
|
108
|
+
if (grain === 'day')
|
|
109
|
+
return span + 1;
|
|
110
|
+
if (grain === 'week')
|
|
111
|
+
return Math.ceil(span / 7) + 1;
|
|
112
|
+
return Math.ceil(span / 28) + 1;
|
|
113
|
+
}
|
|
114
|
+
export function eventRangeDays(range) {
|
|
115
|
+
return (range.endMs - range.startMs) / DAY_MS;
|
|
116
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProtocolDeploymentDatasetAnyVersion } from '@hypequery/protocol';
|
|
2
|
+
/**
|
|
3
|
+
* The physical column a dataset field reads: a column dimension's column, or
|
|
4
|
+
* the name itself otherwise. A contract's time field may name either a
|
|
5
|
+
* dimension or the column one reads, so time-axis checks compare these, as
|
|
6
|
+
* the dataset planner does (RFC 0029).
|
|
7
|
+
*/
|
|
8
|
+
export declare function fieldBackingColumn(dataset: ProtocolDeploymentDatasetAnyVersion, name: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* True when a time axis is visible (RFC 0029). An axis that names a dimension
|
|
11
|
+
* is that dimension, as the planner resolves it, so it is visible only when
|
|
12
|
+
* that dimension is. An axis that names a column no dimension is named after
|
|
13
|
+
* is visible when a visible dimension reads that column. An axis no dimension
|
|
14
|
+
* reads cannot be shown by a policy, so it stays hidden.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isTimeAxisVisible(dataset: ProtocolDeploymentDatasetAnyVersion, axis: string, visibleDimensions: ReadonlySet<string>): boolean;
|
|
17
|
+
//# sourceMappingURL=field-backing-column.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-backing-column.d.ts","sourceRoot":"","sources":["../../src/utils/field-backing-column.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,qBAAqB,CAAC;AAE/E;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mCAAmC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrG;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,mCAAmC,EAC5C,IAAI,EAAE,MAAM,EACZ,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAC,GACrC,OAAO,CAMT"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The physical column a dataset field reads: a column dimension's column, or
|
|
3
|
+
* the name itself otherwise. A contract's time field may name either a
|
|
4
|
+
* dimension or the column one reads, so time-axis checks compare these, as
|
|
5
|
+
* the dataset planner does (RFC 0029).
|
|
6
|
+
*/
|
|
7
|
+
export function fieldBackingColumn(dataset, name) {
|
|
8
|
+
const dimension = dataset.dimensions.find(candidate => String(candidate.name) === name);
|
|
9
|
+
return dimension?.source.kind === 'column' ? dimension.source.column : name;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* True when a time axis is visible (RFC 0029). An axis that names a dimension
|
|
13
|
+
* is that dimension, as the planner resolves it, so it is visible only when
|
|
14
|
+
* that dimension is. An axis that names a column no dimension is named after
|
|
15
|
+
* is visible when a visible dimension reads that column. An axis no dimension
|
|
16
|
+
* reads cannot be shown by a policy, so it stays hidden.
|
|
17
|
+
*/
|
|
18
|
+
export function isTimeAxisVisible(dataset, axis, visibleDimensions) {
|
|
19
|
+
if (visibleDimensions.has(axis))
|
|
20
|
+
return true;
|
|
21
|
+
if (dataset.dimensions.some(dimension => String(dimension.name) === axis))
|
|
22
|
+
return false;
|
|
23
|
+
return dataset.dimensions.some(dimension => (visibleDimensions.has(String(dimension.name)) && fieldBackingColumn(dataset, String(dimension.name)) === axis));
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ProtocolExpression } from '@hypequery/protocol';
|
|
2
|
+
/** One comparison inside a caller filter, with where it sits (RFC 0029). */
|
|
3
|
+
export interface ProtocolFilterLeaf {
|
|
4
|
+
readonly expression: ProtocolExpression;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
/** True under an odd number of `not`s. */
|
|
7
|
+
readonly negated: boolean;
|
|
8
|
+
/** True under any `or` or `not`: such a comparison filters rows but bounds nothing. */
|
|
9
|
+
readonly nested: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Every leaf of a predicate tree, depth first. `and`, `or` and `not` are
|
|
13
|
+
* walked; anything else is a leaf the caller must check is a comparison.
|
|
14
|
+
*/
|
|
15
|
+
export declare function protocolFilterLeaves(expression: ProtocolExpression, path: string): ProtocolFilterLeaf[];
|
|
16
|
+
/**
|
|
17
|
+
* The operators a comparison applies once `not` is pushed down to it. The
|
|
18
|
+
* allowlist is checked against these, so `not` cannot reach an operator a
|
|
19
|
+
* dataset narrowed away.
|
|
20
|
+
*/
|
|
21
|
+
export declare function effectiveFilterOperators(operator: string, negated: boolean): readonly string[];
|
|
22
|
+
//# sourceMappingURL=filter-leaves.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-leaves.d.ts","sourceRoot":"","sources":["../../src/utils/filter-leaves.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,4EAA4E;AAC5E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,uFAAuF;IACvF,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAgBvG;AAeD;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAG9F"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every leaf of a predicate tree, depth first. `and`, `or` and `not` are
|
|
3
|
+
* walked; anything else is a leaf the caller must check is a comparison.
|
|
4
|
+
*/
|
|
5
|
+
export function protocolFilterLeaves(expression, path) {
|
|
6
|
+
const leaves = [];
|
|
7
|
+
const visit = (node, at, negated, nested) => {
|
|
8
|
+
if (node.kind !== 'logical') {
|
|
9
|
+
leaves.push({ expression: node, path: at, negated, nested });
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (node.operator === 'not') {
|
|
13
|
+
visit(node.operand, `${at}.operand`, !negated, true);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const inner = nested || node.operator === 'or';
|
|
17
|
+
node.operands.forEach((operand, index) => visit(operand, `${at}.operands[${index}]`, negated, inner));
|
|
18
|
+
};
|
|
19
|
+
visit(expression, path, false, false);
|
|
20
|
+
return leaves;
|
|
21
|
+
}
|
|
22
|
+
const NEGATED = {
|
|
23
|
+
eq: ['neq'], neq: ['eq'],
|
|
24
|
+
gt: ['lte'], gte: ['lt'], lt: ['gte'], lte: ['gt'],
|
|
25
|
+
in: ['notIn'], notIn: ['in'],
|
|
26
|
+
isNull: ['isNotNull'], isNotNull: ['isNull'],
|
|
27
|
+
between: ['lt', 'gt'],
|
|
28
|
+
// No portable notLike: a filter that allows pattern matching allows its negation.
|
|
29
|
+
like: ['like'],
|
|
30
|
+
// RFC 0029: a relative range resolves to `gte start AND lt end`, and its
|
|
31
|
+
// negation to `lt start OR gte end`: the same pair either way.
|
|
32
|
+
inDateRange: ['gte', 'lt'],
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The operators a comparison applies once `not` is pushed down to it. The
|
|
36
|
+
* allowlist is checked against these, so `not` cannot reach an operator a
|
|
37
|
+
* dataset narrowed away.
|
|
38
|
+
*/
|
|
39
|
+
export function effectiveFilterOperators(operator, negated) {
|
|
40
|
+
if (operator === 'inDateRange')
|
|
41
|
+
return NEGATED.inDateRange;
|
|
42
|
+
return negated ? NEGATED[operator] ?? [operator] : [operator];
|
|
43
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProtocolExpression } from '@hypequery/protocol';
|
|
2
|
+
/**
|
|
3
|
+
* The field a filter expression addresses, or null when it is not a plain
|
|
4
|
+
* comparison.
|
|
5
|
+
*
|
|
6
|
+
* Both operands are checked. A right-hand side that is anything but a literal —
|
|
7
|
+
* another reference, an aggregate, a nested comparison — addresses something
|
|
8
|
+
* this validator never matched against the contract's allowlist, so accepting
|
|
9
|
+
* it would leave a published-surface check to whichever executor happens to be
|
|
10
|
+
* injected. It is also a caller mistake rather than a deployment capability
|
|
11
|
+
* gap, and only a violation raised here reports it as one.
|
|
12
|
+
*/
|
|
13
|
+
export declare function comparisonField(expression: ProtocolExpression): {
|
|
14
|
+
field: string;
|
|
15
|
+
operator: string;
|
|
16
|
+
} | null;
|
|
17
|
+
//# sourceMappingURL=semantic-comparison-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-comparison-field.d.ts","sourceRoot":"","sources":["../../src/utils/semantic-comparison-field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,kBAAkB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAK1G"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The field a filter expression addresses, or null when it is not a plain
|
|
3
|
+
* comparison.
|
|
4
|
+
*
|
|
5
|
+
* Both operands are checked. A right-hand side that is anything but a literal —
|
|
6
|
+
* another reference, an aggregate, a nested comparison — addresses something
|
|
7
|
+
* this validator never matched against the contract's allowlist, so accepting
|
|
8
|
+
* it would leave a published-surface check to whichever executor happens to be
|
|
9
|
+
* injected. It is also a caller mistake rather than a deployment capability
|
|
10
|
+
* gap, and only a violation raised here reports it as one.
|
|
11
|
+
*/
|
|
12
|
+
export function comparisonField(expression) {
|
|
13
|
+
if (expression.kind !== 'comparison' || expression.left.kind !== 'reference')
|
|
14
|
+
return null;
|
|
15
|
+
// A null check (RFC 0023) has no right operand; any other comparison needs a literal one.
|
|
16
|
+
if ('right' in expression && expression.right.kind !== 'literal')
|
|
17
|
+
return null;
|
|
18
|
+
return { field: String(expression.left.name), operator: expression.operator };
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProtocolFilterLeaf } from './filter-leaves.js';
|
|
2
|
+
/**
|
|
3
|
+
* The time-range rule of a time-series query (RFC 0015 window and shift
|
|
4
|
+
* measures, RFC 0029 `fill`), checked against the contract so a caller hears
|
|
5
|
+
* `input-invalid` before anything executes. It mirrors the dataset client:
|
|
6
|
+
* exactly one bounded range on the time axis, made of top-level comparisons.
|
|
7
|
+
*
|
|
8
|
+
* Returns the violation message and path, or `undefined` when the filters
|
|
9
|
+
* bound the axis.
|
|
10
|
+
*/
|
|
11
|
+
export declare function timeSeriesRangeViolation(leaves: readonly ProtocolFilterLeaf[],
|
|
12
|
+
/** True when a leaf compares the time axis, by the column it reads. */
|
|
13
|
+
isOnAxis: (leaf: ProtocolFilterLeaf) => boolean, timeAxis: string, subject: string): {
|
|
14
|
+
message: string;
|
|
15
|
+
path: string;
|
|
16
|
+
} | undefined;
|
|
17
|
+
//# sourceMappingURL=time-series-range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-series-range.d.ts","sourceRoot":"","sources":["../../src/utils/time-series-range.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,kBAAkB,EAAE;AACrC,uEAAuE;AACvE,QAAQ,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,OAAO,EAC/C,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAmB/C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The time-range rule of a time-series query (RFC 0015 window and shift
|
|
3
|
+
* measures, RFC 0029 `fill`), checked against the contract so a caller hears
|
|
4
|
+
* `input-invalid` before anything executes. It mirrors the dataset client:
|
|
5
|
+
* exactly one bounded range on the time axis, made of top-level comparisons.
|
|
6
|
+
*
|
|
7
|
+
* Returns the violation message and path, or `undefined` when the filters
|
|
8
|
+
* bound the axis.
|
|
9
|
+
*/
|
|
10
|
+
export function timeSeriesRangeViolation(leaves,
|
|
11
|
+
/** True when a leaf compares the time axis, by the column it reads. */
|
|
12
|
+
isOnAxis, timeAxis, subject) {
|
|
13
|
+
const onAxis = leaves.filter(isOnAxis);
|
|
14
|
+
const nested = onAxis.find(leaf => leaf.nested);
|
|
15
|
+
if (nested) {
|
|
16
|
+
return {
|
|
17
|
+
message: `${subject} need their time range as top-level filters: a time-axis comparison inside "or" or "not" cannot bound the series.`,
|
|
18
|
+
path: nested.path,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const operators = onAxis.map(leaf => leaf.expression.operator);
|
|
22
|
+
const single = operators.length === 1 && (operators[0] === 'between' || operators[0] === 'inDateRange');
|
|
23
|
+
const pair = operators.length === 2
|
|
24
|
+
&& operators.some(operator => operator === 'gt' || operator === 'gte')
|
|
25
|
+
&& operators.some(operator => operator === 'lt' || operator === 'lte');
|
|
26
|
+
if (single || pair)
|
|
27
|
+
return undefined;
|
|
28
|
+
return {
|
|
29
|
+
message: `${subject} require exactly one bounded range on "${timeAxis}": between, inDateRange, or gt/gte with lt/lte.`,
|
|
30
|
+
path: '$.operation.filters',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProtocolDeploymentDataset, ProtocolVisibleDatasetFields } from '@hypequery/protocol';
|
|
1
|
+
import type { ProtocolDeploymentDataset, ProtocolDeploymentDatasetAnyVersion, ProtocolVisibleDatasetFields } from '@hypequery/protocol';
|
|
2
2
|
type Dimension = ProtocolDeploymentDataset['dimensions'][number];
|
|
3
3
|
/**
|
|
4
4
|
* A dimension the principal may neither group nor filter by, with its label,
|
|
@@ -18,6 +18,6 @@ export declare function concealDimension(dimension: Dimension): Dimension;
|
|
|
18
18
|
* hidden goes with every field it would contribute; a hidden time field and
|
|
19
19
|
* the defaults that depend on it go. The result is still a valid dataset.
|
|
20
20
|
*/
|
|
21
|
-
export declare function narrowDatasetToVisible(dataset:
|
|
21
|
+
export declare function narrowDatasetToVisible<TDataset extends ProtocolDeploymentDatasetAnyVersion>(dataset: TDataset, visible: ProtocolVisibleDatasetFields): TDataset;
|
|
22
22
|
export {};
|
|
23
23
|
//# sourceMappingURL=visibility-projection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visibility-projection.d.ts","sourceRoot":"","sources":["../../src/utils/visibility-projection.ts"],"names":[],"mappings":"
|
|
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,5 @@
|
|
|
1
|
+
import { datasetAllowedFilters, withDatasetAllowedFilters } from '@hypequery/protocol';
|
|
2
|
+
import { isTimeAxisVisible } from './field-backing-column.js';
|
|
1
3
|
/**
|
|
2
4
|
* A dimension the principal may neither group nor filter by, with its label,
|
|
3
5
|
* description and semantic metadata removed (RFC 0019).
|
|
@@ -25,22 +27,43 @@ export function concealDimension(dimension) {
|
|
|
25
27
|
* the defaults that depend on it go. The result is still a valid dataset.
|
|
26
28
|
*/
|
|
27
29
|
export function narrowDatasetToVisible(dataset, visible) {
|
|
28
|
-
const { defaults, timeField, ...rest } = dataset;
|
|
30
|
+
const { defaults, timeField, events, ...rest } = dataset;
|
|
31
|
+
const { alternateTimeFields, ...withoutAlternates } = rest;
|
|
32
|
+
// RFC 0029: an alternate axis shows only beside a visible default axis, and
|
|
33
|
+
// only when a dimension naming it or reading its column is visible, so a
|
|
34
|
+
// hidden one is never named.
|
|
35
|
+
const visibleAlternates = visible.timeField
|
|
36
|
+
? alternateTimeFields?.filter(name => isTimeAxisVisible(dataset, String(name), visible.dimensions))
|
|
37
|
+
: undefined;
|
|
29
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 };
|
|
30
47
|
const narrowedDefaults = {
|
|
31
48
|
...(defaultDimensions === undefined || defaultDimensions.length === 0
|
|
32
49
|
? {}
|
|
33
50
|
: { dimensions: defaultDimensions }),
|
|
34
51
|
...(defaults?.timeGrain === undefined || !visible.timeField ? {} : { timeGrain: defaults.timeGrain }),
|
|
35
52
|
};
|
|
36
|
-
return {
|
|
37
|
-
...
|
|
53
|
+
return withDatasetAllowedFilters({
|
|
54
|
+
...withoutAlternates,
|
|
38
55
|
...(visible.timeField && timeField !== undefined ? { timeField } : {}),
|
|
56
|
+
...(visibleEvents === undefined ? {} : { events: visibleEvents }),
|
|
57
|
+
...(visibleAlternates === undefined || visibleAlternates.length === 0 ? {} : { alternateTimeFields: visibleAlternates }),
|
|
39
58
|
// An empty `defaults` object is not a valid contract value.
|
|
40
59
|
...(Object.keys(narrowedDefaults).length === 0 ? {} : { defaults: narrowedDefaults }),
|
|
41
60
|
dimensions: dataset.dimensions.map(dimension => (visible.dimensions.has(String(dimension.name)) ? dimension : concealDimension(dimension))),
|
|
42
|
-
measures: dataset.measures
|
|
43
|
-
|
|
61
|
+
measures: dataset.measures
|
|
62
|
+
.filter(measure => visible.measures.has(String(measure.name))),
|
|
63
|
+
...(dataset.segments === undefined ? {} : {
|
|
64
|
+
segments: dataset.segments
|
|
65
|
+
.filter(segment => visible.segments?.has(String(segment.name)) ?? true),
|
|
66
|
+
}),
|
|
44
67
|
relationships: dataset.relationships.filter(relationship => (visible.relationships.has(String(relationship.name)))),
|
|
45
|
-
};
|
|
68
|
+
}, datasetAllowedFilters(dataset).filter(filter => visible.filters.has(String(filter.name))));
|
|
46
69
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProtocolDeploymentDatasetAnyVersion, ProtocolSemanticQuery, ProtocolVisibleDatasetFields } from '@hypequery/protocol';
|
|
2
2
|
/**
|
|
3
3
|
* A dataset operation that omits `measures` asks the executor for every base
|
|
4
4
|
* measure of the full contract. When the visibility policy hides any of them,
|
|
@@ -6,5 +6,5 @@ import type { ProtocolDeploymentDataset, ProtocolSemanticQuery, ProtocolVisibleD
|
|
|
6
6
|
* runs is one the visibility check allows. When none is hidden the operation
|
|
7
7
|
* is returned unchanged and keeps the executor's default selection.
|
|
8
8
|
*/
|
|
9
|
-
export declare function withVisibleDefaultMeasures(operation: ProtocolSemanticQuery, dataset:
|
|
9
|
+
export declare function withVisibleDefaultMeasures(operation: ProtocolSemanticQuery, dataset: ProtocolDeploymentDatasetAnyVersion, visible: ProtocolVisibleDatasetFields | undefined): ProtocolSemanticQuery;
|
|
10
10
|
//# sourceMappingURL=visible-measure-selection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visible-measure-selection.d.ts","sourceRoot":"","sources":["../../src/utils/visible-measure-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"visible-measure-selection.d.ts","sourceRoot":"","sources":["../../src/utils/visible-measure-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAQ7B;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,qBAAqB,EAChC,OAAO,EAAE,mCAAmC,EAC5C,OAAO,EAAE,4BAA4B,GAAG,SAAS,GAChD,qBAAqB,CAMvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypequery/deployment",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.1",
|
|
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.30.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^26.6.6",
|
|
33
33
|
"typescript": "^6.0.3",
|
|
34
34
|
"vitest": "^5.1.0",
|
|
35
|
-
"@hypequery/datasets": "0.
|
|
35
|
+
"@hypequery/datasets": "0.35.0"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=20"
|