@hypequery/datasets 0.32.0 → 0.35.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 (264) hide show
  1. package/dist/agent-catalog.d.ts +3 -3
  2. package/dist/agent-catalog.d.ts.map +1 -1
  3. package/dist/cache/protocol-cache-keys.d.ts.map +1 -1
  4. package/dist/cache/protocol-cache-keys.js +10 -48
  5. package/dist/cache/query-signature.d.ts.map +1 -1
  6. package/dist/cache/query-signature.js +16 -5
  7. package/dist/catalog.d.ts +5 -1
  8. package/dist/catalog.d.ts.map +1 -1
  9. package/dist/catalog.js +9 -0
  10. package/dist/client-contract/build-from-deployment.d.ts +2 -2
  11. package/dist/client-contract/build-from-deployment.d.ts.map +1 -1
  12. package/dist/client-contract/build-from-deployment.js +7 -0
  13. package/dist/client-contract/dataset-fields.d.ts.map +1 -1
  14. package/dist/client-contract/dataset-fields.js +2 -1
  15. package/dist/cloud-publication.d.ts +3 -3
  16. package/dist/cloud-publication.d.ts.map +1 -1
  17. package/dist/cloud-publishing.d.ts +2 -2
  18. package/dist/cloud-publishing.d.ts.map +1 -1
  19. package/dist/codegen/dataset-source.d.ts.map +1 -1
  20. package/dist/codegen/dataset-source.js +10 -1
  21. package/dist/contract-3-authoring.fixture.d.ts +103 -0
  22. package/dist/contract-3-authoring.fixture.d.ts.map +1 -0
  23. package/dist/contract-3-authoring.fixture.js +40 -0
  24. package/dist/contract.d.ts +5 -1
  25. package/dist/contract.d.ts.map +1 -1
  26. package/dist/contract.js +9 -0
  27. package/dist/dataset-compilation.d.ts +3 -0
  28. package/dist/dataset-compilation.d.ts.map +1 -1
  29. package/dist/dataset-query.d.ts +5 -0
  30. package/dist/dataset-query.d.ts.map +1 -1
  31. package/dist/dataset.d.ts.map +1 -1
  32. package/dist/dataset.js +12 -2
  33. package/dist/event-operations.d.ts +43 -0
  34. package/dist/event-operations.d.ts.map +1 -0
  35. package/dist/event-operations.js +137 -0
  36. package/dist/execution-capabilities.d.ts +16 -3
  37. package/dist/execution-capabilities.d.ts.map +1 -1
  38. package/dist/execution-capabilities.js +5 -3
  39. package/dist/execution-capabilities.json +7 -8
  40. package/dist/executor.d.ts +13 -0
  41. package/dist/executor.d.ts.map +1 -1
  42. package/dist/executor.js +42 -8
  43. package/dist/index.d.ts +7 -3
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +4 -1
  46. package/dist/portable-execution-errors.d.ts +11 -0
  47. package/dist/portable-execution-errors.d.ts.map +1 -1
  48. package/dist/portable-execution-errors.js +14 -0
  49. package/dist/portable-executor.d.ts +22 -5
  50. package/dist/portable-executor.d.ts.map +1 -1
  51. package/dist/portable-executor.js +64 -5
  52. package/dist/protocol-adapter.d.ts +12 -0
  53. package/dist/protocol-adapter.d.ts.map +1 -1
  54. package/dist/protocol-adapter.js +32 -10
  55. package/dist/protocol-deployment-adapter.d.ts +10 -3
  56. package/dist/protocol-deployment-adapter.d.ts.map +1 -1
  57. package/dist/protocol-deployment-adapter.js +60 -26
  58. package/dist/protocol-rehydrate.d.ts +3 -16
  59. package/dist/protocol-rehydrate.d.ts.map +1 -1
  60. package/dist/protocol-rehydrate.js +72 -14
  61. package/dist/query-builder-protocol.d.ts +10 -0
  62. package/dist/query-builder-protocol.d.ts.map +1 -1
  63. package/dist/query-planner.d.ts.map +1 -1
  64. package/dist/query-planner.js +3 -1
  65. package/dist/relationship-check.d.ts.map +1 -1
  66. package/dist/relationship-check.js +2 -0
  67. package/dist/semantic-planner.d.ts.map +1 -1
  68. package/dist/semantic-planner.js +17 -4
  69. package/dist/semantic-query-schema.d.ts +18 -0
  70. package/dist/semantic-query-schema.d.ts.map +1 -1
  71. package/dist/semantic-query-schema.js +79 -55
  72. package/dist/tools.d.ts +6 -0
  73. package/dist/tools.d.ts.map +1 -1
  74. package/dist/types.d.ts +121 -10
  75. package/dist/types.d.ts.map +1 -1
  76. package/dist/utils/agent-catalog-projection.d.ts +2 -12
  77. package/dist/utils/agent-catalog-projection.d.ts.map +1 -1
  78. package/dist/utils/agent-catalog-projection.js +39 -2
  79. package/dist/utils/build-dataset-query-builder.d.ts.map +1 -1
  80. package/dist/utils/build-dataset-query-builder.js +4 -8
  81. package/dist/utils/calculation-stage-sql.d.ts +31 -0
  82. package/dist/utils/calculation-stage-sql.d.ts.map +1 -0
  83. package/dist/utils/calculation-stage-sql.js +98 -0
  84. package/dist/utils/compile-calculated-dataset-query.d.ts +24 -0
  85. package/dist/utils/compile-calculated-dataset-query.d.ts.map +1 -0
  86. package/dist/utils/compile-calculated-dataset-query.js +133 -0
  87. package/dist/utils/compile-dataset-query.d.ts.map +1 -1
  88. package/dist/utils/compile-dataset-query.js +11 -3
  89. package/dist/utils/dataset-definition-validation.d.ts.map +1 -1
  90. package/dist/utils/dataset-definition-validation.js +94 -7
  91. package/dist/utils/dataset-events.d.ts +19 -0
  92. package/dist/utils/dataset-events.d.ts.map +1 -0
  93. package/dist/utils/dataset-events.js +46 -0
  94. package/dist/utils/dataset-having.d.ts.map +1 -1
  95. package/dist/utils/dataset-having.js +6 -1
  96. package/dist/utils/dataset-query-result.d.ts.map +1 -1
  97. package/dist/utils/dataset-query-result.js +7 -1
  98. package/dist/utils/dataset-query-validation.d.ts +1 -1
  99. package/dist/utils/dataset-query-validation.d.ts.map +1 -1
  100. package/dist/utils/dataset-query-validation.js +25 -47
  101. package/dist/utils/dataset-source.d.ts +2 -2
  102. package/dist/utils/dataset-source.d.ts.map +1 -1
  103. package/dist/utils/dataset-source.js +8 -1
  104. package/dist/utils/dataset-validation.d.ts.map +1 -1
  105. package/dist/utils/dataset-validation.js +2 -1
  106. package/dist/utils/dimension-selection-overrides.d.ts +19 -0
  107. package/dist/utils/dimension-selection-overrides.d.ts.map +1 -0
  108. package/dist/utils/dimension-selection-overrides.js +22 -0
  109. package/dist/utils/event-breakdown-sql.d.ts +15 -0
  110. package/dist/utils/event-breakdown-sql.d.ts.map +1 -0
  111. package/dist/utils/event-breakdown-sql.js +17 -0
  112. package/dist/utils/event-condition-sql.d.ts +18 -0
  113. package/dist/utils/event-condition-sql.d.ts.map +1 -0
  114. package/dist/utils/event-condition-sql.js +63 -0
  115. package/dist/utils/event-operation-shape.d.ts +8 -0
  116. package/dist/utils/event-operation-shape.d.ts.map +1 -0
  117. package/dist/utils/event-operation-shape.js +66 -0
  118. package/dist/utils/event-operation-spec.d.ts +43 -0
  119. package/dist/utils/event-operation-spec.d.ts.map +1 -0
  120. package/dist/utils/event-operation-spec.js +68 -0
  121. package/dist/utils/event-range-span.d.ts +4 -0
  122. package/dist/utils/event-range-span.d.ts.map +1 -0
  123. package/dist/utils/event-range-span.js +22 -0
  124. package/dist/utils/event-result-values.d.ts +8 -0
  125. package/dist/utils/event-result-values.d.ts.map +1 -0
  126. package/dist/utils/event-result-values.js +21 -0
  127. package/dist/utils/event-source-sql.d.ts +38 -0
  128. package/dist/utils/event-source-sql.d.ts.map +1 -0
  129. package/dist/utils/event-source-sql.js +71 -0
  130. package/dist/utils/filter-predicate-tree.d.ts +28 -0
  131. package/dist/utils/filter-predicate-tree.d.ts.map +1 -0
  132. package/dist/utils/filter-predicate-tree.js +80 -0
  133. package/dist/utils/filter-tree.d.ts +42 -0
  134. package/dist/utils/filter-tree.d.ts.map +1 -0
  135. package/dist/utils/filter-tree.js +164 -0
  136. package/dist/utils/filtered-aggregation-sql.d.ts.map +1 -1
  137. package/dist/utils/filtered-aggregation-sql.js +22 -1
  138. package/dist/utils/funnel-rows.d.ts +10 -0
  139. package/dist/utils/funnel-rows.d.ts.map +1 -0
  140. package/dist/utils/funnel-rows.js +30 -0
  141. package/dist/utils/funnel-sql.d.ts +18 -0
  142. package/dist/utils/funnel-sql.d.ts.map +1 -0
  143. package/dist/utils/funnel-sql.js +104 -0
  144. package/dist/utils/metric-derived-query.d.ts.map +1 -1
  145. package/dist/utils/metric-derived-query.js +4 -5
  146. package/dist/utils/metric-query-builder.d.ts.map +1 -1
  147. package/dist/utils/metric-query-builder.js +4 -5
  148. package/dist/utils/metric-query-validation.d.ts.map +1 -1
  149. package/dist/utils/metric-query-validation.js +18 -7
  150. package/dist/utils/other-bucket-sql.d.ts +23 -0
  151. package/dist/utils/other-bucket-sql.d.ts.map +1 -0
  152. package/dist/utils/other-bucket-sql.js +51 -0
  153. package/dist/utils/portable-aggregations.d.ts +10 -6
  154. package/dist/utils/portable-aggregations.d.ts.map +1 -1
  155. package/dist/utils/portable-aggregations.js +13 -8
  156. package/dist/utils/portable-grains.d.ts +17 -8
  157. package/dist/utils/portable-grains.d.ts.map +1 -1
  158. package/dist/utils/portable-grains.js +26 -11
  159. package/dist/utils/portable-query-calculations.d.ts +14 -0
  160. package/dist/utils/portable-query-calculations.d.ts.map +1 -0
  161. package/dist/utils/portable-query-calculations.js +31 -0
  162. package/dist/utils/portable-semantic-query.d.ts.map +1 -1
  163. package/dist/utils/portable-semantic-query.js +27 -1
  164. package/dist/utils/protocol-contract-3.d.ts +30 -0
  165. package/dist/utils/protocol-contract-3.d.ts.map +1 -0
  166. package/dist/utils/protocol-contract-3.js +93 -0
  167. package/dist/utils/protocol-dataset-query.d.ts +19 -0
  168. package/dist/utils/protocol-dataset-query.d.ts.map +1 -0
  169. package/dist/utils/protocol-dataset-query.js +50 -0
  170. package/dist/utils/protocol-filter-nodes.d.ts +9 -0
  171. package/dist/utils/protocol-filter-nodes.d.ts.map +1 -0
  172. package/dist/utils/protocol-filter-nodes.js +68 -0
  173. package/dist/utils/protocol-metric-capabilities.d.ts.map +1 -1
  174. package/dist/utils/protocol-metric-capabilities.js +2 -1
  175. package/dist/utils/protocol-metric-expressions.d.ts +9 -1
  176. package/dist/utils/protocol-metric-expressions.d.ts.map +1 -1
  177. package/dist/utils/protocol-metric-expressions.js +27 -2
  178. package/dist/utils/protocol-rehydrate-filters.d.ts +8 -1
  179. package/dist/utils/protocol-rehydrate-filters.d.ts.map +1 -1
  180. package/dist/utils/protocol-rehydrate-filters.js +20 -1
  181. package/dist/utils/protocol-rehydrate-time-keys.d.ts +6 -0
  182. package/dist/utils/protocol-rehydrate-time-keys.d.ts.map +1 -0
  183. package/dist/utils/protocol-rehydrate-time-keys.js +7 -0
  184. package/dist/utils/query-calculation-errors.d.ts +6 -0
  185. package/dist/utils/query-calculation-errors.d.ts.map +1 -0
  186. package/dist/utils/query-calculation-errors.js +9 -0
  187. package/dist/utils/query-calculation-formula.d.ts +19 -0
  188. package/dist/utils/query-calculation-formula.d.ts.map +1 -0
  189. package/dist/utils/query-calculation-formula.js +77 -0
  190. package/dist/utils/query-calculation-outputs.d.ts +24 -0
  191. package/dist/utils/query-calculation-outputs.d.ts.map +1 -0
  192. package/dist/utils/query-calculation-outputs.js +72 -0
  193. package/dist/utils/query-calculation-plan.d.ts +67 -0
  194. package/dist/utils/query-calculation-plan.d.ts.map +1 -0
  195. package/dist/utils/query-calculation-plan.js +416 -0
  196. package/dist/utils/query-calculation-types.d.ts +97 -0
  197. package/dist/utils/query-calculation-types.d.ts.map +1 -0
  198. package/dist/utils/query-calculation-types.js +8 -0
  199. package/dist/utils/query-field-references.d.ts.map +1 -1
  200. package/dist/utils/query-field-references.js +3 -2
  201. package/dist/utils/query-filter-errors.d.ts +11 -0
  202. package/dist/utils/query-filter-errors.d.ts.map +1 -0
  203. package/dist/utils/query-filter-errors.js +65 -0
  204. package/dist/utils/query-schema-calculations.d.ts +55 -0
  205. package/dist/utils/query-schema-calculations.d.ts.map +1 -0
  206. package/dist/utils/query-schema-calculations.js +150 -0
  207. package/dist/utils/query-schema-filters.d.ts +47 -0
  208. package/dist/utils/query-schema-filters.d.ts.map +1 -0
  209. package/dist/utils/query-schema-filters.js +132 -0
  210. package/dist/utils/query-timezone.d.ts +6 -3
  211. package/dist/utils/query-timezone.d.ts.map +1 -1
  212. package/dist/utils/query-timezone.js +5 -1
  213. package/dist/utils/relationship-builder-plan.d.ts.map +1 -1
  214. package/dist/utils/relationship-builder-plan.js +2 -1
  215. package/dist/utils/relationship-fields.d.ts.map +1 -1
  216. package/dist/utils/relationship-fields.js +5 -0
  217. package/dist/utils/relationship-measure-sql.d.ts.map +1 -1
  218. package/dist/utils/relationship-measure-sql.js +4 -1
  219. package/dist/utils/relationship-measures.d.ts.map +1 -1
  220. package/dist/utils/relationship-measures.js +2 -1
  221. package/dist/utils/relationship-validation.d.ts +3 -1
  222. package/dist/utils/relationship-validation.d.ts.map +1 -1
  223. package/dist/utils/relationship-validation.js +8 -4
  224. package/dist/utils/relative-date-filters.d.ts +21 -0
  225. package/dist/utils/relative-date-filters.d.ts.map +1 -0
  226. package/dist/utils/relative-date-filters.js +86 -0
  227. package/dist/utils/relative-date-range.d.ts +20 -0
  228. package/dist/utils/relative-date-range.d.ts.map +1 -0
  229. package/dist/utils/relative-date-range.js +75 -0
  230. package/dist/utils/retention-rows.d.ts +9 -0
  231. package/dist/utils/retention-rows.d.ts.map +1 -0
  232. package/dist/utils/retention-rows.js +30 -0
  233. package/dist/utils/retention-sql.d.ts +16 -0
  234. package/dist/utils/retention-sql.d.ts.map +1 -0
  235. package/dist/utils/retention-sql.js +68 -0
  236. package/dist/utils/scoped-dataset-source.d.ts.map +1 -1
  237. package/dist/utils/scoped-dataset-source.js +4 -0
  238. package/dist/utils/segments.d.ts +3 -2
  239. package/dist/utils/segments.d.ts.map +1 -1
  240. package/dist/utils/segments.js +5 -4
  241. package/dist/utils/semantic-query-syntax.d.ts.map +1 -1
  242. package/dist/utils/semantic-query-syntax.js +8 -2
  243. package/dist/utils/sql-dataset-source.d.ts +36 -0
  244. package/dist/utils/sql-dataset-source.d.ts.map +1 -0
  245. package/dist/utils/sql-dataset-source.js +126 -0
  246. package/dist/utils/time-axis-bounds.d.ts +11 -4
  247. package/dist/utils/time-axis-bounds.d.ts.map +1 -1
  248. package/dist/utils/time-axis-bounds.js +14 -6
  249. package/dist/utils/time-measure-axis.d.ts +2 -2
  250. package/dist/utils/time-measure-axis.d.ts.map +1 -1
  251. package/dist/utils/time-measure-axis.js +13 -3
  252. package/dist/utils/time-measure-dataset-sql.d.ts +1 -1
  253. package/dist/utils/time-measure-dataset-sql.d.ts.map +1 -1
  254. package/dist/utils/time-measure-dataset-sql.js +15 -5
  255. package/dist/utils/time-measure-source-sql.d.ts +2 -2
  256. package/dist/utils/time-measure-source-sql.d.ts.map +1 -1
  257. package/dist/utils/time-measure-source-sql.js +7 -8
  258. package/dist/utils/time-query-measures.d.ts +5 -0
  259. package/dist/utils/time-query-measures.d.ts.map +1 -1
  260. package/dist/utils/time-query-measures.js +7 -0
  261. package/dist/utils/unsupported-contract-reasons.d.ts +5 -1
  262. package/dist/utils/unsupported-contract-reasons.d.ts.map +1 -1
  263. package/dist/utils/unsupported-contract-reasons.js +5 -1
  264. package/package.json +3 -3
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Query-scoped calculations (RFC 0026) as the dataset client accepts them.
3
+ *
4
+ * The shapes mirror the portable query envelope, except that a `filter`
5
+ * calculation's `where` uses the client's `{ field, operator, value }`
6
+ * filters, exactly as `DatasetQuery.filters` does.
7
+ */
8
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"query-field-references.d.ts","sourceRoot":"","sources":["../../src/utils/query-field-references.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAgB,MAAM,aAAa,CAAC;AASlF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,EAAE,CAsB/F"}
1
+ {"version":3,"file":"query-field-references.d.ts","sourceRoot":"","sources":["../../src/utils/query-field-references.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAgB,MAAM,aAAa,CAAC;AASlF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,EAAE,CAsB/F"}
@@ -1,3 +1,4 @@
1
+ import { filterLeaves } from './filter-tree.js';
1
2
  import { baseMeasureNames, isBaseMeasure } from './dataset-measures.js';
2
3
  import { measureDependencies } from './measure-dependencies.js';
3
4
  import { segmentFilters } from './segments.js';
@@ -14,7 +15,7 @@ function filterField(dataset, filter) {
14
15
  export function queryFieldReferences(dataset, query) {
15
16
  const names = [
16
17
  ...(query.dimensions ?? []),
17
- ...(query.filters ?? []).map(filter => filterField(dataset, filter)),
18
+ ...filterLeaves(query.filters).map(filter => filterField(dataset, filter)),
18
19
  ...segmentFilters(dataset, query.segments).map(filter => filterField(dataset, filter)),
19
20
  ...(query.orderBy ?? []).map(order => order.field),
20
21
  ...(query.having ?? []).map(condition => condition.measure),
@@ -30,7 +31,7 @@ export function queryFieldReferences(dataset, query) {
30
31
  const definition = dataset.measures[name];
31
32
  measureDependencies(definition).forEach(visit);
32
33
  if (isBaseMeasure(definition)) {
33
- names.push(...(definition.filters ?? []).map(filter => filterField(dataset, filter)));
34
+ names.push(...filterLeaves(definition.filters).map(filter => filterField(dataset, filter)));
34
35
  }
35
36
  };
36
37
  (query.measures ?? baseMeasureNames(dataset.measures)).forEach(visit);
@@ -0,0 +1,11 @@
1
+ import type { AnyDatasetInstance, DatasetFilterNode, ExecutionContext } from '../types.js';
2
+ /**
3
+ * Why each comparison of a filter tree cannot apply to `ds`: an unknown or
4
+ * disallowed field or operator (under `not`, the negated operator the
5
+ * allowlist must permit), a value of the wrong type, an unresolved relative
6
+ * range, or the tenant field under runtime tenancy. Query `filters` and RFC
7
+ * 0026 filter calculations share these rules; a malformed tree is reported by
8
+ * `filterTreeErrors`, not here.
9
+ */
10
+ export declare function queryFilterErrors(ds: AnyDatasetInstance, queryFilters: readonly DatasetFilterNode[], context?: ExecutionContext): string[];
11
+ //# sourceMappingURL=query-filter-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-filter-errors.d.ts","sourceRoot":"","sources":["../../src/utils/query-filter-errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAW3F;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,kBAAkB,EACtB,YAAY,EAAE,SAAS,iBAAiB,EAAE,EAC1C,OAAO,CAAC,EAAE,gBAAgB,GACzB,MAAM,EAAE,CAyDV"}
@@ -0,0 +1,65 @@
1
+ import { validateFilterValue } from '../validation.js';
2
+ import { SEMANTIC_FILTER_OPERATORS } from '../constants.js';
3
+ import { getRuntimeTenantPredicate } from './tenant-runtime.js';
4
+ import { isQualifiedField } from './relationship-fields.js';
5
+ import { validateQualifiedFilter } from './relationship-validation.js';
6
+ import { filterAllowsOperator } from './filter-operator-policy.js';
7
+ import { effectiveFilters } from './effective-filters.js';
8
+ import { effectiveFilterLeaves } from './filter-tree.js';
9
+ import { relativeDateFilterError } from './relative-date-filters.js';
10
+ /**
11
+ * Why each comparison of a filter tree cannot apply to `ds`: an unknown or
12
+ * disallowed field or operator (under `not`, the negated operator the
13
+ * allowlist must permit), a value of the wrong type, an unresolved relative
14
+ * range, or the tenant field under runtime tenancy. Query `filters` and RFC
15
+ * 0026 filter calculations share these rules; a malformed tree is reported by
16
+ * `filterTreeErrors`, not here.
17
+ */
18
+ export function queryFilterErrors(ds, queryFilters, context) {
19
+ const errors = [];
20
+ const filters = effectiveFilters(ds);
21
+ const filterNames = Object.keys(filters);
22
+ for (const { filter, operators } of effectiveFilterLeaves(queryFilters)) {
23
+ // The client resolves every valid relative range first (RFC 0029); one
24
+ // still here could not be resolved, and says why.
25
+ if (filter.operator === 'inDateRange') {
26
+ errors.push(relativeDateFilterError(ds, filter) ?? `Filter "${filter.field}": "inDateRange" was not resolved before validation.`);
27
+ continue;
28
+ }
29
+ if (isQualifiedField(filter.field)) {
30
+ const filterError = validateQualifiedFilter(ds, filter, context, operators);
31
+ if (filterError) {
32
+ errors.push(filterError);
33
+ }
34
+ continue;
35
+ }
36
+ if (!filterNames.includes(filter.field)) {
37
+ errors.push(`Unknown filter fields: ${filter.field}. Available: ${filterNames.join(', ')}`);
38
+ continue;
39
+ }
40
+ const filterDefinition = filters[filter.field];
41
+ const refused = operators.find(operator => !filterAllowsOperator(filterDefinition, operator));
42
+ if (refused) {
43
+ errors.push(`Filter "${filter.field}" does not allow operator "${refused}"${refused === filter.operator ? '' : ` (the negation of "${filter.operator}")`}. Allowed: ${(filterDefinition?.operators ?? SEMANTIC_FILTER_OPERATORS).join(', ')}`);
44
+ continue;
45
+ }
46
+ const resolvedField = filterDefinition.field;
47
+ const resolvedDimension = ds.dimensions[resolvedField];
48
+ const resolvedColumn = resolvedDimension?.sql
49
+ ? undefined
50
+ : resolvedDimension?.column ?? resolvedField;
51
+ if (getRuntimeTenantPredicate(context) && ds.tenantKey && resolvedColumn === ds.tenantKey) {
52
+ errors.push(`Cannot filter on tenant field "${filter.field}" when runtime tenancy enforcement is active.`);
53
+ continue;
54
+ }
55
+ const fieldType = resolvedDimension?.fieldType;
56
+ if (!fieldType) {
57
+ continue;
58
+ }
59
+ const filterError = validateFilterValue(filter, fieldType);
60
+ if (filterError) {
61
+ errors.push(filterError);
62
+ }
63
+ }
64
+ return errors;
65
+ }
@@ -0,0 +1,55 @@
1
+ import { z, type ZodTypeAny } from 'zod';
2
+ import type { DatasetQuery } from '../types.js';
3
+ export interface CalculationSchemaFields {
4
+ /** Groupable dimensions: what `rank.within`, `share.of` and `limitBy.by` may name. */
5
+ readonly dimensions: readonly string[];
6
+ /** Whether the dataset has a time axis, so `period` is a grouping key under a grain. */
7
+ readonly hasTime: boolean;
8
+ /** Base measures a filter calculation may condition. */
9
+ readonly filterMeasures: readonly string[];
10
+ /** Base and derived measures `other` may rank by. */
11
+ readonly bucketMeasures: readonly string[];
12
+ /** Local string dimensions `other` may bucket. */
13
+ readonly bucketDimensions: readonly string[];
14
+ /** Comparison shapes a filter calculation's `where` accepts. */
15
+ readonly whereVariants: readonly ZodTypeAny[];
16
+ /** Most calculation entries one query may carry. */
17
+ readonly maxCalculations?: number;
18
+ }
19
+ interface MeasureSource {
20
+ readonly measures: Readonly<Record<string, {
21
+ readonly aggregation?: string;
22
+ readonly kind?: string;
23
+ }>>;
24
+ readonly derivedMeasures?: Readonly<Record<string, unknown>>;
25
+ }
26
+ /**
27
+ * The measures a calculation may name by field: a filter calculation's base
28
+ * measure (local, neither window nor shift, and filterable), and what `other`
29
+ * ranks by (a base or derived measure).
30
+ */
31
+ export declare function calculationMeasures(source: MeasureSource): Pick<CalculationSchemaFields, 'filterMeasures' | 'bucketMeasures'>;
32
+ /** A simple identifier (RFC 0002): what a calculation is named. */
33
+ export declare function identifierSchema(): ZodTypeAny;
34
+ /**
35
+ * A measure or an earlier output. Its grammar and what it resolves to are the
36
+ * planner's to check, so the schema spends no bytes repeating the pattern.
37
+ */
38
+ export declare function referenceSchema(): ZodTypeAny;
39
+ /**
40
+ * `calculations`, `limitBy` and `other` for a dataset query. Each is left out
41
+ * when the dataset has nothing it could name, so no advertised option is one
42
+ * every call would fail.
43
+ */
44
+ export declare function calculationShape(fields: CalculationSchemaFields): Record<string, ZodTypeAny>;
45
+ /**
46
+ * `orderBy` and `having` may name a calculation output as well as a published
47
+ * field. Outputs are named by the query itself, so whether a name is one is
48
+ * checked here, against the calculations the call carries.
49
+ */
50
+ export declare function refineCalculationReferences(input: Pick<DatasetQuery, 'calculations' | 'orderBy' | 'having'>, published: {
51
+ readonly orderable: ReadonlySet<string>;
52
+ readonly measures: ReadonlySet<string>;
53
+ }, context: z.RefinementCtx): void;
54
+ export {};
55
+ //# sourceMappingURL=query-schema-calculations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-schema-calculations.d.ts","sourceRoot":"","sources":["../../src/utils/query-schema-calculations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAEzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAoBhD,MAAM,WAAW,uBAAuB;IACtC,sFAAsF;IACtF,QAA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AAQ,CAAC,EAChE,SAAS,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAE,EAC9F,OAAO,EAAE,CAAC,CAAC,aAAa,GACvB,IAAI,CAoBN"}
@@ -0,0 +1,150 @@
1
+ import { z } from 'zod';
2
+ import { SUPPORTED_TIME_GRAINS } from '../constants.js';
3
+ import { calculationOutputs } from './query-calculation-outputs.js';
4
+ import { fieldEnum } from './query-schema-filters.js';
5
+ /**
6
+ * Schemas for RFC 0026 query-scoped calculations, `limitBy` and `other` on a
7
+ * dataset query input. Field names stay enums of the dataset's fields; an
8
+ * input reference may also name an earlier entry's output, which the caller
9
+ * names, so it is an identifier and the planner checks what it resolves to.
10
+ */
11
+ const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
12
+ const FORMULA_OPERATORS = [
13
+ 'add', 'subtract', 'multiply', 'divide', 'nullIfZero', 'coalesce', 'round', 'floor', 'ceil', 'percentChange',
14
+ ];
15
+ /** RFC 0026 ceilings: shift and trailing amounts, `other.n`, and the remainder label. */
16
+ const MAX_INTERVAL = 1000;
17
+ const MAX_OTHER = 1000;
18
+ const MAX_LABEL = 64;
19
+ /** Base aggregations a filter calculation cannot condition, as for model-level filtered measures. */
20
+ const UNFILTERABLE_AGGREGATIONS = new Set(['argMax', 'argMin', 'merge']);
21
+ /**
22
+ * The measures a calculation may name by field: a filter calculation's base
23
+ * measure (local, neither window nor shift, and filterable), and what `other`
24
+ * ranks by (a base or derived measure).
25
+ */
26
+ export function calculationMeasures(source) {
27
+ const base = Object.entries(source.measures).filter(([, entry]) => entry.kind === undefined && entry.aggregation !== undefined);
28
+ return {
29
+ filterMeasures: base.filter(([, entry]) => !UNFILTERABLE_AGGREGATIONS.has(entry.aggregation)).map(([name]) => name),
30
+ bucketMeasures: [...base.map(([name]) => name), ...Object.keys(source.derivedMeasures ?? {})],
31
+ };
32
+ }
33
+ /** A simple identifier (RFC 0002): what a calculation is named. */
34
+ export function identifierSchema() {
35
+ return z.string().regex(IDENTIFIER);
36
+ }
37
+ /**
38
+ * A measure or an earlier output. Its grammar and what it resolves to are the
39
+ * planner's to check, so the schema spends no bytes repeating the pattern.
40
+ */
41
+ export function referenceSchema() {
42
+ return z.string();
43
+ }
44
+ function union(schemas) {
45
+ return schemas.length === 1 ? schemas[0] : z.union(schemas);
46
+ }
47
+ /** Exactly one of `keys` is present on `value`. */
48
+ function exactlyOne(value, keys) {
49
+ return keys.filter(key => value[key] !== undefined).length === 1;
50
+ }
51
+ /**
52
+ * One entry: a `name` and exactly one kind member. A single object with every
53
+ * kind optional, rather than one object per kind, keeps `name` and the
54
+ * object's framing in the schema once; the "exactly one" rule is checked here.
55
+ */
56
+ function calculationEntry(fields) {
57
+ const reference = referenceSchema();
58
+ const unit = z.enum(SUPPORTED_TIME_GRAINS);
59
+ const amount = z.number().int().min(1).max(MAX_INTERVAL);
60
+ const partition = z.array(fieldEnum([...fields.dimensions, ...(fields.hasTime ? ['period'] : [])])).optional();
61
+ const formula = z.object({
62
+ op: z.enum(FORMULA_OPERATORS),
63
+ get args() { return z.array(z.union([reference, z.number().finite(), formula])).min(1).max(2); },
64
+ }).strict();
65
+ const windowModes = ['trailing', 'toDate', 'cumulative'];
66
+ const kinds = {
67
+ ...(fields.filterMeasures.length > 0 && fields.whereVariants.length > 0 ? {
68
+ filter: z.object({
69
+ measure: fieldEnum(fields.filterMeasures),
70
+ where: z.array(union(fields.whereVariants)).min(1),
71
+ }).strict(),
72
+ } : {}),
73
+ ...(fields.hasTime ? {
74
+ shift: z.object({ measure: reference, amount, unit }).strict(),
75
+ window: z.object({
76
+ measure: reference,
77
+ trailing: z.object({ amount, unit }).strict().optional(),
78
+ toDate: z.enum(SUPPORTED_TIME_GRAINS.filter(grain => grain !== 'minute')).optional(),
79
+ cumulative: z.literal(true).optional(),
80
+ }).strict().refine(window => exactlyOne(window, windowModes), 'Use exactly one of trailing, toDate or cumulative.').describe('Exactly one of trailing, toDate or cumulative.'),
81
+ compare: z.object({
82
+ to: z.enum(['previousPeriod', 'previousYear']),
83
+ measures: z.array(reference).min(1),
84
+ }).strict(),
85
+ } : {}),
86
+ formula,
87
+ rank: z.object({ measure: reference, within: partition, direction: z.enum(['asc', 'desc']).optional() }).strict(),
88
+ share: z.object({ measure: reference, of: partition }).strict(),
89
+ };
90
+ const names = Object.keys(kinds);
91
+ return z.object({
92
+ name: identifierSchema(),
93
+ ...Object.fromEntries(Object.entries(kinds).map(([kind, schema]) => [kind, schema.optional()])),
94
+ }).strict().refine(value => exactlyOne(value, names), `Give each calculation exactly one of ${names.join(', ')}.`);
95
+ }
96
+ /**
97
+ * `calculations`, `limitBy` and `other` for a dataset query. Each is left out
98
+ * when the dataset has nothing it could name, so no advertised option is one
99
+ * every call would fail.
100
+ */
101
+ export function calculationShape(fields) {
102
+ const groupKeys = [...fields.dimensions, ...(fields.hasTime ? ['period'] : [])];
103
+ const calculations = z.array(calculationEntry(fields));
104
+ return {
105
+ calculations: (fields.maxCalculations === undefined ? calculations : calculations.max(fields.maxCalculations))
106
+ .optional()
107
+ .describe('Each is a name and exactly one kind. Inputs name a selected measure or an earlier output; '
108
+ + 'shift, window and compare need grain and a time range filter. Outputs can be ordered by and used in having.'),
109
+ ...(groupKeys.length > 0 ? {
110
+ limitBy: z.object({
111
+ n: z.number().int().positive(),
112
+ by: z.array(fieldEnum(groupKeys)).min(1),
113
+ }).strict().optional().describe('Keep the first n rows of each by group, in orderBy order (orderBy required).'),
114
+ } : {}),
115
+ ...(fields.bucketDimensions.length > 0 && fields.bucketMeasures.length > 0 ? {
116
+ other: z.object({
117
+ dimension: fieldEnum(fields.bucketDimensions),
118
+ n: z.number().int().min(1).max(MAX_OTHER),
119
+ measure: fieldEnum(fields.bucketMeasures),
120
+ label: z.string().min(1).max(MAX_LABEL).optional(),
121
+ }).strict().optional().describe('Keep the top n values of a selected dimension by measure; group the rest under label (default "Other").'),
122
+ } : {}),
123
+ };
124
+ }
125
+ /**
126
+ * `orderBy` and `having` may name a calculation output as well as a published
127
+ * field. Outputs are named by the query itself, so whether a name is one is
128
+ * checked here, against the calculations the call carries.
129
+ */
130
+ export function refineCalculationReferences(input, published, context) {
131
+ const outputs = new Set(calculationOutputs(input).map(output => output.name));
132
+ input.orderBy?.forEach((order, index) => {
133
+ if (!published.orderable.has(order.field) && !outputs.has(order.field)) {
134
+ context.addIssue({
135
+ code: 'custom',
136
+ path: ['orderBy', index, 'field'],
137
+ message: 'Not a field this dataset can order by, or an output of this query\'s calculations.',
138
+ });
139
+ }
140
+ });
141
+ input.having?.forEach((condition, index) => {
142
+ if (!published.measures.has(condition.measure) && !outputs.has(condition.measure)) {
143
+ context.addIssue({
144
+ code: 'custom',
145
+ path: ['having', index, 'measure'],
146
+ message: 'Not a measure of this dataset, or an output of this query\'s calculations.',
147
+ });
148
+ }
149
+ });
150
+ }
@@ -0,0 +1,47 @@
1
+ import { type ZodTypeAny } from 'zod';
2
+ import type { FilterPolicy } from './effective-filters.js';
3
+ /** Every relative range of the RFC 0029 grammar without a count. */
4
+ export declare const RELATIVE_DATE_RANGES: readonly string[];
5
+ export interface FilterLeafOptions {
6
+ /**
7
+ * One comparison shape per distinct operator set rather than per field,
8
+ * with the fields as an enum. Accepts exactly the same filters in fewer
9
+ * bytes; off where existing schemas must stay byte-identical.
10
+ */
11
+ readonly compact?: boolean;
12
+ /** Fields that also accept `inDateRange` with a relative range value. */
13
+ readonly relativeDateFields?: readonly string[];
14
+ }
15
+ export declare function fieldEnum(values: readonly string[]): ZodTypeAny;
16
+ /** The RFC 0029 relative range grammar: the fixed forms as an enum, `last N units` as a pattern. */
17
+ export declare function relativeDateRangeSchema(): ZodTypeAny;
18
+ /** Comparison variants: a value form and, where allowed, a value-free null check (RFC 0023). */
19
+ export declare function filterLeafVariants(localFilters: Readonly<Record<string, FilterPolicy>>, fields: readonly string[], relationshipOperators: ReadonlyMap<string, string[]>, options?: FilterLeafOptions): ZodTypeAny[];
20
+ /** The schema of one top-level `filters` item. */
21
+ export declare function filterItemSchema(variants: readonly ZodTypeAny[], options?: {
22
+ readonly groups?: boolean;
23
+ }): ZodTypeAny;
24
+ interface TimeAxisSource {
25
+ readonly name?: string;
26
+ readonly timeKey?: string;
27
+ readonly timeKeys?: readonly string[];
28
+ readonly dimensions: Readonly<Record<string, {
29
+ readonly column?: string;
30
+ readonly type?: string;
31
+ }>>;
32
+ }
33
+ /** Whether a local filter reads a timestamp dimension, through its own name or an alias. */
34
+ export declare function isTimestampFilter(source: TimeAxisSource, localFilters: Readonly<Record<string, FilterPolicy>>, field: string): boolean;
35
+ /**
36
+ * Whether a local filter compares one of the dataset's time axes. Compared by
37
+ * backing column, as the planner reads the axis: a filter or a `timeKey` may
38
+ * name a column that a differently named dimension reads.
39
+ */
40
+ export declare function isTimeAxisFilter(source: TimeAxisSource, localFilters: Readonly<Record<string, FilterPolicy>>, field: string): boolean;
41
+ /**
42
+ * The filters that compare a time axis and allow both `gte` and `lt`, the
43
+ * effective operators of `inDateRange`.
44
+ */
45
+ export declare function relativeDateFilterFields(source: TimeAxisSource, localFilters: Readonly<Record<string, FilterPolicy>>, fields: readonly string[]): string[];
46
+ export {};
47
+ //# sourceMappingURL=query-schema-filters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-schema-filters.d.ts","sourceRoot":"","sources":["../../src/utils/query-schema-filters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAIzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAU3D,oEAAoE;AACpE,eAAO,MAAM,oBAAoB,mBAQ/B,CAAC;AAKH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,yEAAyE;IACzE,QAAQ,CAAC,kBAAkB,CAAC,EA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AAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,EACpD,KAAK,EAAE,MAAM,GACZ,OAAO,CAKT;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,EACpD,MAAM,EAAE,SAAS,MAAM,EAAE,GACxB,MAAM,EAAE,CAMV"}
@@ -0,0 +1,132 @@
1
+ import { z } from 'zod';
2
+ import { isNullCheckFilterOperator, SEMANTIC_FILTER_OPERATORS } from '../constants.js';
3
+ import { uniqueSorted } from './canonical-json.js';
4
+ import { datasetTimeKeys } from './dataset-time-keys.js';
5
+ /**
6
+ * Caller filter schemas for semantic query inputs: one comparison per field
7
+ * with that field's operators, and optionally `inDateRange` on time axes and
8
+ * `and` / `or` / `not` groups over them (RFC 0029).
9
+ */
10
+ const RELATIVE_DATE_UNITS = ['day', 'week', 'month', 'quarter', 'year'];
11
+ /** Every relative range of the RFC 0029 grammar without a count. */
12
+ export const RELATIVE_DATE_RANGES = Object.freeze([
13
+ 'today',
14
+ 'yesterday',
15
+ ...RELATIVE_DATE_UNITS.map(unit => `this ${unit}`),
16
+ ...RELATIVE_DATE_UNITS.map(unit => `last ${unit}`),
17
+ 'month to date',
18
+ 'quarter to date',
19
+ 'year to date',
20
+ ]);
21
+ /** `last <N> <unit>(s)`, the counted form, N from 1 to 9999. */
22
+ const LAST_N = /^last [1-9][0-9]{0,3} (day|week|month|quarter|year)s?$/;
23
+ export function fieldEnum(values) {
24
+ const unique = uniqueSorted([...values]);
25
+ return unique.length > 0
26
+ ? z.enum(unique)
27
+ : z.never();
28
+ }
29
+ /** The RFC 0029 relative range grammar: the fixed forms as an enum, `last N units` as a pattern. */
30
+ export function relativeDateRangeSchema() {
31
+ return z.union([
32
+ z.enum(RELATIVE_DATE_RANGES),
33
+ z.string().regex(LAST_N),
34
+ ]).describe('Resolved by the server in the query timezone. "last N days" ends before today.');
35
+ }
36
+ function operatorsFor(field, localFilters, relationshipOperators) {
37
+ return relationshipOperators.has(field)
38
+ ? relationshipOperators.get(field) ?? []
39
+ : localFilters[field]?.operators ?? [...SEMANTIC_FILTER_OPERATORS];
40
+ }
41
+ /** Comparison variants: a value form and, where allowed, a value-free null check (RFC 0023). */
42
+ export function filterLeafVariants(localFilters, fields, relationshipOperators, options = {}) {
43
+ const filterValue = z.unknown().refine(value => value !== undefined, 'Required');
44
+ // Fields with the same operators share a shape when compact; otherwise each
45
+ // field is its own group, as the original per-field form has it.
46
+ const groups = new Map();
47
+ for (const field of uniqueSorted([...fields])) {
48
+ const operators = operatorsFor(field, localFilters, relationshipOperators);
49
+ const key = options.compact ? uniqueSorted([...operators]).join(',') : field;
50
+ const group = groups.get(key) ?? { fields: [], operators };
51
+ group.fields.push(field);
52
+ groups.set(key, group);
53
+ }
54
+ const variants = [...groups.values()].flatMap(({ fields: names, operators }) => {
55
+ const field = names.length === 1 ? z.literal(names[0]) : fieldEnum(names);
56
+ const valueOperators = operators.filter(operator => !isNullCheckFilterOperator(operator));
57
+ const nullChecks = operators.filter(isNullCheckFilterOperator);
58
+ return [
59
+ ...(valueOperators.length > 0 || nullChecks.length === 0
60
+ ? [z.object({ field, operator: fieldEnum(valueOperators), value: filterValue }).strict()]
61
+ : []),
62
+ ...(nullChecks.length > 0
63
+ ? [z.object({ field, operator: fieldEnum(nullChecks) }).strict()]
64
+ : []),
65
+ ];
66
+ });
67
+ const relative = options.relativeDateFields ?? [];
68
+ if (relative.length > 0) {
69
+ variants.push(z.object({
70
+ field: relative.length === 1 ? z.literal(relative[0]) : fieldEnum(relative),
71
+ operator: z.literal('inDateRange'),
72
+ value: relativeDateRangeSchema(),
73
+ }).strict());
74
+ }
75
+ return variants;
76
+ }
77
+ /** The schema of one top-level `filters` item. */
78
+ export function filterItemSchema(variants, options = {}) {
79
+ if (variants.length === 0) {
80
+ return z.object({
81
+ field: z.never(),
82
+ operator: z.enum(SEMANTIC_FILTER_OPERATORS),
83
+ value: z.unknown().refine(value => value !== undefined, 'Required'),
84
+ }).strict();
85
+ }
86
+ if (!options.groups) {
87
+ return variants.length === 1
88
+ ? variants[0]
89
+ : z.union(variants);
90
+ }
91
+ // A group's items are comparisons or further groups, so the schema refers
92
+ // to itself; JSON Schema carries that as one `$ref`'d definition rather than
93
+ // repeating every comparison at each level.
94
+ // Getters rather than `z.lazy`, so JSON Schema refers to the definition
95
+ // directly instead of wrapping each reference in an `allOf`.
96
+ const node = z.union([
97
+ ...variants,
98
+ z.object({ get and() { return z.array(node).min(1); } }).strict(),
99
+ z.object({ get or() { return z.array(node).min(1); } }).strict(),
100
+ z.object({ get not() { return node; } }).strict(),
101
+ ]).describe('A comparison, or { and: [...] }, { or: [...] } or { not: ... } over them.');
102
+ return node;
103
+ }
104
+ /** Whether a local filter reads a timestamp dimension, through its own name or an alias. */
105
+ export function isTimestampFilter(source, localFilters, field) {
106
+ const resolved = localFilters[field]?.field ?? field;
107
+ return source.dimensions[resolved]?.type === 'timestamp';
108
+ }
109
+ /**
110
+ * Whether a local filter compares one of the dataset's time axes. Compared by
111
+ * backing column, as the planner reads the axis: a filter or a `timeKey` may
112
+ * name a column that a differently named dimension reads.
113
+ */
114
+ export function isTimeAxisFilter(source, localFilters, field) {
115
+ if (field.includes('.'))
116
+ return false;
117
+ const column = (name) => source.dimensions[name]?.column ?? name;
118
+ const resolved = column(localFilters[field]?.field ?? field);
119
+ return datasetTimeKeys(source).some(key => column(key) === resolved);
120
+ }
121
+ /**
122
+ * The filters that compare a time axis and allow both `gte` and `lt`, the
123
+ * effective operators of `inDateRange`.
124
+ */
125
+ export function relativeDateFilterFields(source, localFilters, fields) {
126
+ return uniqueSorted(fields.filter((field) => {
127
+ if (!Object.hasOwn(localFilters, field) || !isTimeAxisFilter(source, localFilters, field))
128
+ return false;
129
+ const operators = localFilters[field].operators ?? SEMANTIC_FILTER_OPERATORS;
130
+ return operators.includes('gte') && operators.includes('lt');
131
+ }));
132
+ }
@@ -1,8 +1,11 @@
1
1
  import type { DatasetSqlDialectRules } from '../dataset-sql-dialect.js';
2
- import type { AnyDatasetInstance, MetricFilter, MetricFilterOperator } from '../types.js';
2
+ import type { AnyDatasetInstance } from '../types.js';
3
+ import type { PlannedFilter, PlannedFilterOperator } from './filter-predicate-tree.js';
3
4
  /** Named zones only: reject fixed offsets, invalid zones, and SQL fragments. */
4
5
  export declare function isQueryTimezone(value: unknown): value is string;
5
6
  export declare function queryTimezoneErrors(timezone: unknown): string[];
7
+ /** The canonical IANA name a query zone is rendered as; `UTC` when absent. */
8
+ export declare function queryTimezoneName(timezone: string | undefined): string;
6
9
  /** Conversion preserves timestamp instants and interprets Date values as local dates. */
7
10
  export declare function queryTimeSql(dialect: DatasetSqlDialectRules, expression: string, timezone: string | undefined): string;
8
11
  /** True when a local filter field reads one of the dataset's time-axis columns. */
@@ -13,7 +16,7 @@ export declare function queryTimeFilterSql(dialect: DatasetSqlDialectRules, ds:
13
16
  export interface QueryTimePredicate {
14
17
  /** The column side of the predicate, converted to a zone when the value needs one. */
15
18
  readonly expression: string;
16
- readonly operator: MetricFilterOperator;
19
+ readonly operator: PlannedFilterOperator;
17
20
  /** The value to bind, with instants rewritten to the wall clock of that zone. */
18
21
  readonly value: unknown;
19
22
  }
@@ -43,5 +46,5 @@ export interface QueryTimeFilterOptions {
43
46
  * changes a member's meaning. Non-timestamp fields and `like` patterns are
44
47
  * bound unchanged.
45
48
  */
46
- export declare function queryTimeFilter(dialect: DatasetSqlDialectRules, ds: AnyDatasetInstance, filter: MetricFilter, expression: string, timezone: string | undefined, options?: QueryTimeFilterOptions): QueryTimePredicate[];
49
+ export declare function queryTimeFilter(dialect: DatasetSqlDialectRules, ds: AnyDatasetInstance, filter: PlannedFilter, expression: string, timezone: string | undefined, options?: QueryTimeFilterOptions): QueryTimePredicate[];
47
50
  //# sourceMappingURL=query-timezone.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-timezone.d.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B,CAAC;IACzC,iFAAiF;IACjF,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;CACzC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,sBAAsB,EAC/B,EAAE,EAAE,kBAAkB,EACtB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,OAAO,GAAE,sBAA2B,GACnC,kBAAkB,EAAE,CA0CtB"}
@@ -26,6 +26,10 @@ function canonicalTimezone(timezone) {
26
26
  throw new Error(errors[0]);
27
27
  return new Intl.DateTimeFormat('en', { timeZone: timezone }).resolvedOptions().timeZone;
28
28
  }
29
+ /** The canonical IANA name a query zone is rendered as; `UTC` when absent. */
30
+ export function queryTimezoneName(timezone) {
31
+ return canonicalTimezone(timezone);
32
+ }
29
33
  /** Conversion preserves timestamp instants and interprets Date values as local dates. */
30
34
  export function queryTimeSql(dialect, expression, timezone) {
31
35
  return dialect.toQueryTimezone(expression, canonicalTimezone(timezone));
@@ -70,7 +74,7 @@ export function queryTimeFilter(dialect, ds, filter, expression, timezone, optio
70
74
  : expression;
71
75
  const local = { expression: localExpression, operator: filter.operator, value: filter.value };
72
76
  // A null check has no value to read in any zone.
73
- if (fieldType !== 'timestamp' || filter.operator === 'like'
77
+ if (fieldType !== 'timestamp' || filter.operator === 'like' || filter.operator === 'notLike'
74
78
  || filter.operator === 'isNull' || filter.operator === 'isNotNull')
75
79
  return [local];
76
80
  const values = Array.isArray(filter.value) ? filter.value : [filter.value];
@@ -1 +1 @@
1
- {"version":3,"file":"relationship-builder-plan.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-builder-plan.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,a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,0BAA0B,GAAG,SAAS,CAmDxC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,0BAA0B,GAAG,SAAS,EAC3C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,MAAM,CAER;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,0BAA0B,GAC9B,MAAM,CAaR;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,gBAAgB,EACpB,GAAG,EAAE,0BAA0B,GAAG,SAAS,GAC1C,gBAAgB,CAoClB"}
1
+ {"version":3,"file":"relationship-builder-plan.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-builder-plan.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAIxE;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAuC,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAG7F,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,YAAY,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;IAClC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,4EAA4E;IAC5E,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,uFAAuF;IACvF,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC7B,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACrD,oEAAoE;IACpE,OAAO,EAAE,sBAAsB,CAAC;CACjC;AAED,KAAK,SAAS,GAAG,IAAI,CAAC,YAAY,GAAG,WAAW,EAAE,YAAY,GAAG,SAAS,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAEzH;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,gBAAgB,EAC1B,OAAO,GAAE,sBAAoD,GAC5D,0BAA0B,GAAG,SAAS,CAmDxC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,0BAA0B,GAAG,SAAS,EAC3C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,MAAM,CAER;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,0BAA0B,GAC9B,MAAM,CAaR;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,gBAAgB,EACpB,GAAG,EAAE,0BAA0B,GAAG,SAAS,GAC1C,gBAAgB,CAoClB"}
@@ -1,3 +1,4 @@
1
+ import { filterLeaves } from './filter-tree.js';
1
2
  import { relationshipKeys } from './relationship-keys.js';
2
3
  import { relationshipJoinSource } from './relationship-measure-sql.js';
3
4
  import { clickhouseDatasetSqlDialect } from './clickhouse-dataset-sql-dialect.js';
@@ -15,7 +16,7 @@ export function buildRelationshipBuilderContext(ds, query, context, dialect = cl
15
16
  const referenced = [
16
17
  ...(query.dimensions ?? []),
17
18
  ...(query.measures ?? []),
18
- ...(query.filters ?? []).map((filter) => filter.field),
19
+ ...filterLeaves(query.filters).map((filter) => filter.field),
19
20
  ...(query.orderBy ?? []).map((order) => order.field),
20
21
  ...runtimeConstraints(context).map((constraint) => constraint.field),
21
22
  ].filter(isQualifiedField);
@@ -1 +1 @@
1
- {"version":3,"file":"relationship-fields.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,sBAAsB,GACnC,MAAM,EAAE,CAEV;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,sBAAsB,GACnC,MAAM,EAAE,CAEV;AAgBD,MAAM,WAAW,oBAAoB;IACnC,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;CACf;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI,CAM7E;AAED,MAAM,WAAW,sBAAsB;IACrC,8EAA8E;IAC9E,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,sBAAsB,CAAC;IACrC,4CAA4C;IAC5C,MAAM,EAAE,kBAAkB,CAAC;IAC3B,+DAA+D;IAC/D,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,mBAAmB,CAAC;IACrC,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,wBAAwB,GAChC;IAAE,QAAQ,EAAE,sBAAsB,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,MAAM,GACX,wBAAwB,GAAG,IAAI,CA2DjC"}
1
+ {"version":3,"file":"relationship-fields.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,sBAAsB,GACnC,MAAM,EAAE,CAEV;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,sBAAsB,GACnC,MAAM,EAAE,CAEV;AAgBD,MAAM,WAAW,oBAAoB;IACnC,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;CACf;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI,CAM7E;AAED,MAAM,WAAW,sBAAsB;IACrC,8EAA8E;IAC9E,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,sBAAsB,CAAC;IACrC,4CAA4C;IAC5C,MAAM,EAAE,kBAAkB,CAAC;IAC3B,+DAA+D;IAC/D,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,mBAAmB,CAAC;IACrC,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,wBAAwB,GAChC;IAAE,QAAQ,EAAE,sBAAsB,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,MAAM,GACX,wBAAwB,GAAG,IAAI,CAgEjC"}
@@ -86,6 +86,11 @@ export function resolveQualifiedField(ds, name) {
86
86
  };
87
87
  }
88
88
  const target = relationship.target();
89
+ if (target.sqlSource) {
90
+ return {
91
+ error: `Relationship "${relationshipName}" on dataset "${ds.name}" targets "${target.name}", which reads a SQL source; SQL-sourced datasets can't be relationship targets yet (RFC 0028).`,
92
+ };
93
+ }
89
94
  const targetDimension = Object.hasOwn(target.dimensions, field)
90
95
  ? target.dimensions[field]
91
96
  : undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"relationship-measure-sql.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-measure-sql.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,aAAa,CAAC;AAEvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAIjF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAExE;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,kBAAkB,EAAE,EAAE,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,sBAAsB;;;EAsBlJ;AAeD,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,0BAA0B,EAAE,OAAO,EAAE,sBAAsB;;;;EAexJ"}
1
+ {"version":3,"file":"relationship-measure-sql.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-measure-sql.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,aAAa,CAAC;AAEvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAIjF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAExE;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,kBAAkB,EAAE,EAAE,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,sBAAsB;;;EAsBlJ;AAgBD,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,0BAA0B,EAAE,OAAO,EAAE,sBAAsB;;;;EAexJ"}