@camunda/ccma-shared-types 5.0.0 → 7.0.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 (100) hide show
  1. package/dist/_tests/approvals/dns-subdomain.spec.d.ts +1 -0
  2. package/dist/_tests/approvals/expected-value.spec.d.ts +1 -0
  3. package/dist/_tests/charts/chart-query.spec.d.ts +1 -0
  4. package/dist/_tests/constants/customer-hardware-sizing.const.spec.d.ts +1 -0
  5. package/dist/_tests/dashboards/definition.spec.d.ts +1 -0
  6. package/dist/_tests/dtos/ClusterPlanWhiteList.spec.d.ts +1 -0
  7. package/dist/_tests/utils/elasticsearchPlanPath.utils.spec.d.ts +1 -0
  8. package/dist/_tests/utils/upgradeGateReason.utils.spec.d.ts +1 -0
  9. package/dist/approvals/dns-subdomain.d.ts +12 -0
  10. package/dist/approvals/dns-subdomain.js +16 -0
  11. package/dist/approvals/dns-subdomain.js.map +7 -0
  12. package/dist/approvals/expected-value.d.ts +33 -0
  13. package/dist/approvals/expected-value.js +26 -0
  14. package/dist/approvals/expected-value.js.map +7 -0
  15. package/dist/approvals/policy.js +1 -1
  16. package/dist/approvals/policy.js.map +2 -2
  17. package/dist/approvals/use-cases.const.d.ts +96 -0
  18. package/dist/approvals/use-cases.const.js +59 -2
  19. package/dist/approvals/use-cases.const.js.map +2 -2
  20. package/dist/charts/chart-metrics.d.ts +35 -0
  21. package/dist/charts/chart-metrics.js +188 -0
  22. package/dist/charts/chart-metrics.js.map +7 -0
  23. package/dist/charts/chart-query.d.ts +55 -0
  24. package/dist/charts/chart-query.js +376 -0
  25. package/dist/charts/chart-query.js.map +7 -0
  26. package/dist/charts/chart-spec.d.ts +103 -0
  27. package/dist/charts/chart-spec.js +79 -0
  28. package/dist/charts/chart-spec.js.map +7 -0
  29. package/dist/charts/index.d.ts +3 -0
  30. package/dist/charts/index.js +59 -0
  31. package/dist/charts/index.js.map +7 -0
  32. package/dist/constants/customer-hardware-sizing.const.d.ts +124 -0
  33. package/dist/constants/customer-hardware-sizing.const.js +266 -0
  34. package/dist/constants/customer-hardware-sizing.const.js.map +7 -0
  35. package/dist/constants/version-gates.const.d.ts +12 -0
  36. package/dist/constants/version-gates.const.js +2 -0
  37. package/dist/constants/version-gates.const.js.map +2 -2
  38. package/dist/dashboards/definition.d.ts +86 -0
  39. package/dist/dashboards/definition.js +137 -0
  40. package/dist/dashboards/definition.js.map +7 -0
  41. package/dist/dtos/Annotation.dto.d.ts +1 -1
  42. package/dist/dtos/Annotation.dto.js +10 -2
  43. package/dist/dtos/Annotation.dto.js.map +2 -2
  44. package/dist/dtos/ApprovalJob.dto.d.ts +33 -3
  45. package/dist/dtos/ApprovalJob.dto.js.map +2 -2
  46. package/dist/dtos/ClusterPlanTypeChange.dto.d.ts +23 -0
  47. package/dist/dtos/ClusterPlanTypeChange.dto.js +1 -0
  48. package/dist/dtos/ClusterPlanTypeChange.dto.js.map +7 -0
  49. package/dist/dtos/CommonCluster.dto.d.ts +5 -0
  50. package/dist/dtos/ControlV2.dto.d.ts +17 -0
  51. package/dist/dtos/Dashboard.dto.d.ts +336 -0
  52. package/dist/dtos/Dashboard.dto.js +70 -0
  53. package/dist/dtos/Dashboard.dto.js.map +7 -0
  54. package/dist/dtos/EarlyAccessFeature.dto.d.ts +1 -0
  55. package/dist/dtos/FeatureFlags.dto.d.ts +96 -54
  56. package/dist/dtos/Hdp.dto.d.ts +5 -88
  57. package/dist/dtos/Organization.dto.d.ts +21 -0
  58. package/dist/dtos/Organization.dto.js.map +1 -1
  59. package/dist/dtos/SalesPlan.dto.d.ts +18 -0
  60. package/dist/dtos/SalesPlan.dto.js +18 -0
  61. package/dist/dtos/SalesPlan.dto.js.map +2 -2
  62. package/dist/dtos/UpgradeReadiness.dto.d.ts +32 -0
  63. package/dist/dtos/UpgradeReadiness.dto.js +1 -0
  64. package/dist/dtos/UpgradeReadiness.dto.js.map +7 -0
  65. package/dist/enums/SystemAuditEntity.enum.d.ts +5 -2
  66. package/dist/enums/SystemAuditEntity.enum.js +3 -0
  67. package/dist/enums/SystemAuditEntity.enum.js.map +2 -2
  68. package/dist/index.d.ts +18 -5
  69. package/dist/index.js +192 -1
  70. package/dist/index.js.map +2 -2
  71. package/dist/permissions/accounts.permissions.d.ts +12 -0
  72. package/dist/permissions/accounts.permissions.js +11 -0
  73. package/dist/permissions/accounts.permissions.js.map +2 -2
  74. package/dist/permissions/combo.js +5 -0
  75. package/dist/permissions/combo.js.map +2 -2
  76. package/dist/search/compiler.d.ts +20 -0
  77. package/dist/search/compiler.js +48 -11
  78. package/dist/search/compiler.js.map +2 -2
  79. package/dist/search/index.d.ts +1 -1
  80. package/dist/search/index.js.map +2 -2
  81. package/dist/search/organization-search-fields.d.ts +5 -2
  82. package/dist/search/organization-search-fields.js +9 -1
  83. package/dist/search/organization-search-fields.js.map +2 -2
  84. package/dist/search/parser.d.ts +3 -0
  85. package/dist/search/parser.js +3 -1
  86. package/dist/search/parser.js.map +2 -2
  87. package/dist/types/ClusterBulkOperation.type.d.ts +14 -0
  88. package/dist/types/ClusterPlanFields.type.js +74 -74
  89. package/dist/types/ClusterPlanFields.type.js.map +2 -2
  90. package/dist/utils/elasticsearchPlanPath.utils.d.ts +20 -0
  91. package/dist/utils/elasticsearchPlanPath.utils.js +32 -0
  92. package/dist/utils/elasticsearchPlanPath.utils.js.map +7 -0
  93. package/dist/utils/qa-user.utils.d.ts +14 -0
  94. package/dist/utils/qa-user.utils.js +14 -0
  95. package/dist/utils/qa-user.utils.js.map +7 -0
  96. package/dist/utils/qa-user.utils.spec.d.ts +1 -0
  97. package/dist/utils/upgradeGateReason.utils.d.ts +8 -0
  98. package/dist/utils/upgradeGateReason.utils.js +23 -0
  99. package/dist/utils/upgradeGateReason.utils.js.map +7 -0
  100. package/package.json +1 -1
@@ -0,0 +1,188 @@
1
+ const CLUSTER_DIMENSION = {
2
+ id: "cluster",
3
+ label: "Cluster",
4
+ description: "The cluster id."
5
+ };
6
+ const ORG_DIMENSION = {
7
+ id: "org",
8
+ label: "Organization",
9
+ description: "The organization id."
10
+ };
11
+ const ORG_NAME_DIMENSION = {
12
+ id: "orgName",
13
+ label: "Organization name",
14
+ description: "The name of the organization of the cluster. Prod clusters only: on other stages it is (unknown)."
15
+ };
16
+ const ORG_ID_FILTER = {
17
+ field: "orgId",
18
+ label: "Organization id",
19
+ description: "Exact organization id.",
20
+ type: "string",
21
+ capabilities: ["match"],
22
+ example: "orgId:3f2c\u2026"
23
+ };
24
+ const CLUSTER_ID_FILTER = {
25
+ field: "clusterId",
26
+ label: "Cluster id",
27
+ description: "Exact cluster id.",
28
+ type: "string",
29
+ capabilities: ["match"],
30
+ example: "clusterId:9a1b\u2026"
31
+ };
32
+ const VALUE_METRIC_DIMENSIONS = [
33
+ CLUSTER_DIMENSION,
34
+ ORG_DIMENSION,
35
+ ORG_NAME_DIMENSION,
36
+ {
37
+ id: "salesPlan",
38
+ label: "Sales plan",
39
+ description: "The sales plan of the organization on that day."
40
+ },
41
+ {
42
+ id: "env",
43
+ label: "Environment",
44
+ description: "Production or development cluster."
45
+ }
46
+ ];
47
+ const VALUE_METRIC_FILTERS = [
48
+ ORG_ID_FILTER,
49
+ CLUSTER_ID_FILTER,
50
+ {
51
+ field: "salesPlan",
52
+ label: "Sales plan",
53
+ description: "Sales plan name, case-insensitive. Use * as a wildcard.",
54
+ type: "string",
55
+ capabilities: ["match"],
56
+ example: "salesPlan:enterprise*"
57
+ },
58
+ {
59
+ field: "env",
60
+ label: "Environment",
61
+ description: "Production or development cluster.",
62
+ type: "enum",
63
+ capabilities: ["match"],
64
+ enumValues: ["production", "development"],
65
+ example: "env:production"
66
+ }
67
+ ];
68
+ const ALL_GRAINS = ["day", "week", "month"];
69
+ const VALUE_METRIC_GRAINS = ALL_GRAINS;
70
+ const LARGE_TABLE_MAX_WINDOW_DAYS = 400;
71
+ const gaugeMetric = (id, label, unit, stat, description) => ({
72
+ id,
73
+ label,
74
+ description,
75
+ unit,
76
+ dimensions: [CLUSTER_DIMENSION, ORG_DIMENSION, ORG_NAME_DIMENSION],
77
+ filters: [ORG_ID_FILTER, CLUSTER_ID_FILTER],
78
+ grains: ALL_GRAINS,
79
+ maxWindowDays: LARGE_TABLE_MAX_WINDOW_DAYS,
80
+ stat
81
+ });
82
+ const VALUE_METRIC_MAX_WINDOW_DAYS = 762;
83
+ const valueMetric = (id, label, description) => ({
84
+ id,
85
+ label,
86
+ description,
87
+ unit: "count",
88
+ dimensions: VALUE_METRIC_DIMENSIONS,
89
+ filters: VALUE_METRIC_FILTERS,
90
+ grains: VALUE_METRIC_GRAINS,
91
+ maxWindowDays: VALUE_METRIC_MAX_WINDOW_DAYS,
92
+ stat: { series: "sum", window: "sum" }
93
+ });
94
+ const CHART_METRICS = [
95
+ valueMetric(
96
+ "processInstances",
97
+ "Process instances",
98
+ "Process instances that started, from the HDP value metrics. The sum over each bucket."
99
+ ),
100
+ valueMetric(
101
+ "decisionInstances",
102
+ "Decision instances",
103
+ "Decision instances that ran, from the HDP value metrics. The sum over each bucket."
104
+ ),
105
+ valueMetric(
106
+ "taskUsers",
107
+ "Task users",
108
+ "Task users, from the HDP value metrics. The sum of the daily values over each bucket, as on the Value metrics tab."
109
+ ),
110
+ gaugeMetric(
111
+ "activeTenants",
112
+ "Active tenants",
113
+ "count",
114
+ { series: "sum", window: "max" },
115
+ "Active tenants: the peak of each cluster on a day, summed over the clusters. A week or a month shows its highest day. The table holds every stage."
116
+ ),
117
+ gaugeMetric(
118
+ "clusterLoad",
119
+ "Cluster load",
120
+ "percent",
121
+ { series: "mean", window: "mean" },
122
+ "The load of a cluster, in percent: the mean of a day, then the mean over the clusters and the days of a bucket. The table holds every stage."
123
+ ),
124
+ gaugeMetric(
125
+ "diskUsedBytes",
126
+ "Elasticsearch disk used",
127
+ "bytes",
128
+ { series: "sum", window: "max" },
129
+ "The used Elasticsearch disk: the peak of each cluster on a day, summed over the clusters. A week or a month shows its highest day. The table holds every stage."
130
+ ),
131
+ {
132
+ id: "hostingCost",
133
+ label: "Hosting cost",
134
+ description: "The loaded hosting cost of the clusters, in US dollars, from the cloud bill. The sum over each bucket. The bill holds every stage.",
135
+ unit: "usd",
136
+ dimensions: [CLUSTER_DIMENSION, ORG_DIMENSION, ORG_NAME_DIMENSION],
137
+ filters: [ORG_ID_FILTER, CLUSTER_ID_FILTER],
138
+ grains: ALL_GRAINS,
139
+ maxWindowDays: VALUE_METRIC_MAX_WINDOW_DAYS,
140
+ stat: { series: "sum", window: "sum" }
141
+ },
142
+ {
143
+ id: "changeEvents",
144
+ label: "Change events",
145
+ description: "The change events that the backends of this stage sent to HDP: one for each insert, update or delete of an entity. The count over each bucket.",
146
+ unit: "count",
147
+ dimensions: [
148
+ { id: "entity", label: "Entity", description: "For example cluster." },
149
+ {
150
+ id: "operation",
151
+ label: "Operation",
152
+ description: "insert, update or delete."
153
+ }
154
+ ],
155
+ filters: [
156
+ {
157
+ field: "entity",
158
+ label: "Entity",
159
+ description: "The entity, case-insensitive. Use * as a wildcard.",
160
+ type: "string",
161
+ capabilities: ["match"],
162
+ example: "entity:cluster"
163
+ },
164
+ {
165
+ field: "operation",
166
+ label: "Operation",
167
+ description: "The operation.",
168
+ type: "enum",
169
+ capabilities: ["match"],
170
+ enumValues: ["insert", "update", "delete"],
171
+ example: "operation:delete"
172
+ }
173
+ ],
174
+ grains: ALL_GRAINS,
175
+ maxWindowDays: LARGE_TABLE_MAX_WINDOW_DAYS,
176
+ stat: { series: "sum", window: "sum" }
177
+ }
178
+ ];
179
+ const findChartMetric = (id, metrics = CHART_METRICS) => metrics.find((metric) => metric.id.toLowerCase() === id.toLowerCase());
180
+ const findChartDimension = (metric, id) => metric.dimensions.find(
181
+ (dimension) => dimension.id.toLowerCase() === id.toLowerCase()
182
+ );
183
+ export {
184
+ CHART_METRICS,
185
+ findChartDimension,
186
+ findChartMetric
187
+ };
188
+ //# sourceMappingURL=chart-metrics.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/charts/chart-metrics.ts"],
4
+ "sourcesContent": ["/*\n * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH\n * under one or more contributor license agreements. Licensed under a commercial license.\n * You may not use this file except in compliance with the commercial license.\n */\n\nimport type { SearchFieldSpec } from '../search/fields.js'\nimport type { ChartGrain, ChartUnit } from './chart-spec.js'\n\n// ============================================================================\n// The metric catalogue of the chart tiles, without SQL.\n//\n// The frontend reads it for autocomplete, help and validation as you type.\n// accounts-backend pairs each entry with its SQL (`hdp-data.charts.controller`),\n// and a test there makes sure that the two have the same ids.\n// ============================================================================\n\nexport interface ChartDimensionSpec {\n /** As typed after `by`. */\n id: string\n label: string\n description: string\n}\n\nexport interface ChartMetricSpec {\n /** As typed at the start of a query. */\n id: string\n label: string\n description: string\n unit: ChartUnit\n dimensions: readonly ChartDimensionSpec[]\n /** The fields that `where` can use. */\n filters: readonly SearchFieldSpec[]\n grains: readonly ChartGrain[]\n /** The longest window, in days. */\n maxWindowDays: number\n /**\n * How one number comes from a chart, for the `stat` render: first over the\n * series of a bucket, then over the buckets of the window. A counter sums\n * both. A gauge must not: a sum of daily load percentages means nothing.\n */\n stat: { series: 'sum' | 'mean'; window: 'sum' | 'max' | 'mean' }\n}\n\nconst CLUSTER_DIMENSION: ChartDimensionSpec = {\n id: 'cluster',\n label: 'Cluster',\n description: 'The cluster id.',\n}\n\nconst ORG_DIMENSION: ChartDimensionSpec = {\n id: 'org',\n label: 'Organization',\n description: 'The organization id.',\n}\n\n/**\n * The name of the organization of the cluster. It comes from the clusters\n * table of HDP, which holds the prod clusters only, so on another stage every\n * series is `(unknown)`.\n */\nconst ORG_NAME_DIMENSION: ChartDimensionSpec = {\n id: 'orgName',\n label: 'Organization name',\n description:\n 'The name of the organization of the cluster. Prod clusters only: on other stages it is (unknown).',\n}\n\nconst ORG_ID_FILTER: SearchFieldSpec = {\n field: 'orgId',\n label: 'Organization id',\n description: 'Exact organization id.',\n type: 'string',\n capabilities: ['match'],\n example: 'orgId:3f2c\u2026',\n}\n\nconst CLUSTER_ID_FILTER: SearchFieldSpec = {\n field: 'clusterId',\n label: 'Cluster id',\n description: 'Exact cluster id.',\n type: 'string',\n capabilities: ['match'],\n example: 'clusterId:9a1b\u2026',\n}\n\nconst VALUE_METRIC_DIMENSIONS: readonly ChartDimensionSpec[] = [\n CLUSTER_DIMENSION,\n ORG_DIMENSION,\n ORG_NAME_DIMENSION,\n {\n id: 'salesPlan',\n label: 'Sales plan',\n description: 'The sales plan of the organization on that day.',\n },\n {\n id: 'env',\n label: 'Environment',\n description: 'Production or development cluster.',\n },\n]\n\nconst VALUE_METRIC_FILTERS: readonly SearchFieldSpec[] = [\n ORG_ID_FILTER,\n CLUSTER_ID_FILTER,\n {\n field: 'salesPlan',\n label: 'Sales plan',\n description: 'Sales plan name, case-insensitive. Use * as a wildcard.',\n type: 'string',\n capabilities: ['match'],\n example: 'salesPlan:enterprise*',\n },\n {\n field: 'env',\n label: 'Environment',\n description: 'Production or development cluster.',\n type: 'enum',\n capabilities: ['match'],\n enumValues: ['production', 'development'],\n example: 'env:production',\n },\n]\n\nconst ALL_GRAINS: readonly ChartGrain[] = ['day', 'week', 'month']\nconst VALUE_METRIC_GRAINS = ALL_GRAINS\n\n/**\n * About one year, for a metric on a large table: the cluster gauges, which\n * are scraped about once a minute, and the change events of every backend\n * and stage. `over 12m every month` starts on the 1st of a month and reads up\n * to 396 days, so the limit holds that query.\n */\nconst LARGE_TABLE_MAX_WINDOW_DAYS = 400\n\n/** A gauge of the clusters, from the Prometheus metrics in HDP. */\nconst gaugeMetric = (\n id: string,\n label: string,\n unit: ChartMetricSpec['unit'],\n stat: ChartMetricSpec['stat'],\n description: string,\n): ChartMetricSpec => ({\n id,\n label,\n description,\n unit,\n dimensions: [CLUSTER_DIMENSION, ORG_DIMENSION, ORG_NAME_DIMENSION],\n filters: [ORG_ID_FILTER, CLUSTER_ID_FILTER],\n grains: ALL_GRAINS,\n maxWindowDays: LARGE_TABLE_MAX_WINDOW_DAYS,\n stat,\n})\n\n/**\n * About two years. The table holds one row for each cluster, day and metric.\n * `over 24m every month` starts on the 1st of a month and reads up to 761\n * days, so the limit holds that query.\n */\nconst VALUE_METRIC_MAX_WINDOW_DAYS = 762\n\nconst valueMetric = (\n id: string,\n label: string,\n description: string,\n): ChartMetricSpec => ({\n id,\n label,\n description,\n unit: 'count',\n dimensions: VALUE_METRIC_DIMENSIONS,\n filters: VALUE_METRIC_FILTERS,\n grains: VALUE_METRIC_GRAINS,\n maxWindowDays: VALUE_METRIC_MAX_WINDOW_DAYS,\n stat: { series: 'sum', window: 'sum' },\n})\n\nexport const CHART_METRICS: readonly ChartMetricSpec[] = [\n valueMetric(\n 'processInstances',\n 'Process instances',\n 'Process instances that started, from the HDP value metrics. The sum over each bucket.',\n ),\n valueMetric(\n 'decisionInstances',\n 'Decision instances',\n 'Decision instances that ran, from the HDP value metrics. The sum over each bucket.',\n ),\n valueMetric(\n 'taskUsers',\n 'Task users',\n 'Task users, from the HDP value metrics. The sum of the daily values over each bucket, as on the Value metrics tab.',\n ),\n gaugeMetric(\n 'activeTenants',\n 'Active tenants',\n 'count',\n { series: 'sum', window: 'max' },\n 'Active tenants: the peak of each cluster on a day, summed over the clusters. A week or a month shows its highest day. The table holds every stage.',\n ),\n gaugeMetric(\n 'clusterLoad',\n 'Cluster load',\n 'percent',\n { series: 'mean', window: 'mean' },\n 'The load of a cluster, in percent: the mean of a day, then the mean over the clusters and the days of a bucket. The table holds every stage.',\n ),\n gaugeMetric(\n 'diskUsedBytes',\n 'Elasticsearch disk used',\n 'bytes',\n { series: 'sum', window: 'max' },\n 'The used Elasticsearch disk: the peak of each cluster on a day, summed over the clusters. A week or a month shows its highest day. The table holds every stage.',\n ),\n {\n id: 'hostingCost',\n label: 'Hosting cost',\n description:\n 'The loaded hosting cost of the clusters, in US dollars, from the cloud bill. The sum over each bucket. The bill holds every stage.',\n unit: 'usd',\n dimensions: [CLUSTER_DIMENSION, ORG_DIMENSION, ORG_NAME_DIMENSION],\n filters: [ORG_ID_FILTER, CLUSTER_ID_FILTER],\n grains: ALL_GRAINS,\n maxWindowDays: VALUE_METRIC_MAX_WINDOW_DAYS,\n stat: { series: 'sum', window: 'sum' },\n },\n {\n id: 'changeEvents',\n label: 'Change events',\n description:\n 'The change events that the backends of this stage sent to HDP: one for each insert, update or delete of an entity. The count over each bucket.',\n unit: 'count',\n dimensions: [\n { id: 'entity', label: 'Entity', description: 'For example cluster.' },\n {\n id: 'operation',\n label: 'Operation',\n description: 'insert, update or delete.',\n },\n ],\n filters: [\n {\n field: 'entity',\n label: 'Entity',\n description: 'The entity, case-insensitive. Use * as a wildcard.',\n type: 'string',\n capabilities: ['match'],\n example: 'entity:cluster',\n },\n {\n field: 'operation',\n label: 'Operation',\n description: 'The operation.',\n type: 'enum',\n capabilities: ['match'],\n enumValues: ['insert', 'update', 'delete'],\n example: 'operation:delete',\n },\n ],\n grains: ALL_GRAINS,\n maxWindowDays: LARGE_TABLE_MAX_WINDOW_DAYS,\n stat: { series: 'sum', window: 'sum' },\n },\n]\n\n/** Case-insensitive. */\nexport const findChartMetric = (\n id: string,\n metrics: readonly ChartMetricSpec[] = CHART_METRICS,\n): ChartMetricSpec | undefined =>\n metrics.find((metric) => metric.id.toLowerCase() === id.toLowerCase())\n\n/** Case-insensitive. */\nexport const findChartDimension = (\n metric: ChartMetricSpec,\n id: string,\n): ChartDimensionSpec | undefined =>\n metric.dimensions.find(\n (dimension) => dimension.id.toLowerCase() === id.toLowerCase(),\n )\n"],
5
+ "mappings": "AA4CA,MAAM,oBAAwC;AAAA,EAC5C,IAAI;AAAA,EACJ,OAAO;AAAA,EACP,aAAa;AACf;AAEA,MAAM,gBAAoC;AAAA,EACxC,IAAI;AAAA,EACJ,OAAO;AAAA,EACP,aAAa;AACf;AAOA,MAAM,qBAAyC;AAAA,EAC7C,IAAI;AAAA,EACJ,OAAO;AAAA,EACP,aACE;AACJ;AAEA,MAAM,gBAAiC;AAAA,EACrC,OAAO;AAAA,E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;AAAA,QACN,cAAc,CAAC,OAAO;AAAA,QACtB,SAAS;AAAA,MACX;AAAA,MACA;AAAA,QACE,OAAO;AAAA,QACP,OAAO;AAAA,QACP,aAAa;AAAA,QACb,MAAM;AAAA,QACN,cAAc,CAAC,OAAO;AAAA,QACtB,YAAY,CAAC,UAAU,UAAU,QAAQ;AAAA,QACzC,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,MAAM,EAAE,QAAQ,OAAO,QAAQ,MAAM;AAAA,EACvC;AACF;AAGO,MAAM,kBAAkB,CAC7B,IACA,UAAsC,kBAEtC,QAAQ,KAAK,CAAC,WAAW,OAAO,GAAG,YAAY,MAAM,GAAG,YAAY,CAAC;AAGhE,MAAM,qBAAqB,CAChC,QACA,OAEA,OAAO,WAAW;AAAA,EAChB,CAAC,cAAc,UAAU,GAAG,YAAY,MAAM,GAAG,YAAY;AAC/D;",
6
+ "names": []
7
+ }
@@ -0,0 +1,55 @@
1
+ import { type ChartMetricSpec } from './chart-metrics.js';
2
+ import { type ChartSpec } from './chart-spec.js';
3
+ export type ChartQueryErrorKind = 'syntax' | 'unknown-metric' | 'unknown-dimension' | 'unknown-field' | 'bad-value';
4
+ export declare class ChartQueryError extends Error {
5
+ readonly kind: ChartQueryErrorKind;
6
+ /** A name to use instead, for "did you mean". */
7
+ readonly suggestion?: string;
8
+ constructor(message: string, kind: ChartQueryErrorKind, suggestion?: string);
9
+ }
10
+ /** Type guard that works across package boundaries. */
11
+ export declare const isChartQueryError: (error: unknown) => error is ChartQueryError;
12
+ /**
13
+ * The answer of `POST /api/dashboards/chart-queries/check`: the canonical spec
14
+ * of a valid query, or what is wrong with a query and how to fix it. A wrong
15
+ * query is an answer and not a failure, so a client reads `valid`.
16
+ */
17
+ export type ChartQueryCheck = {
18
+ valid: true;
19
+ spec: ChartSpec;
20
+ query: string;
21
+ } | {
22
+ valid: false;
23
+ error: {
24
+ kind: ChartQueryErrorKind;
25
+ message: string;
26
+ suggestion?: string;
27
+ };
28
+ };
29
+ export interface ChartQueryOptions {
30
+ metrics?: readonly ChartMetricSpec[];
31
+ /** `YYYY-MM-DD`. The default is today in UTC. */
32
+ today?: string;
33
+ }
34
+ /**
35
+ * Parse and validate a chart query. Gives the canonical {@link ChartSpec}:
36
+ * the ids in the spelling of the catalogue, and the defaults filled in.
37
+ * Throws {@link ChartQueryError}.
38
+ */
39
+ export declare const parseChartQuery: (text: string, options?: ChartQueryOptions) => ChartSpec;
40
+ /**
41
+ * Check a spec against the catalogue and give it in canonical form. The chart
42
+ * route runs this on every request body, so a spec that a tile stored long ago
43
+ * gets the rules of today. Throws {@link ChartQueryError}.
44
+ */
45
+ export declare const validateChartSpec: (spec: ChartSpec, options?: ChartQueryOptions) => ChartSpec;
46
+ /**
47
+ * The text of a spec, in one canonical form. Parsing it again gives the same
48
+ * spec, so the text field and the builder can never disagree.
49
+ */
50
+ export declare const formatChartSpec: (spec: ChartSpec) => string;
51
+ /**
52
+ * Read a spec from JSON, for example a request body or a stored tile. Checks
53
+ * the shape only. Run {@link validateChartSpec} after it.
54
+ */
55
+ export declare const readChartSpec: (value: unknown) => ChartSpec;
@@ -0,0 +1,376 @@
1
+ import { isLuceneQueryError } from "../search/ast.js";
2
+ import { closestField } from "../search/compiler.js";
3
+ import { findSearchField } from "../search/fields.js";
4
+ import { parseLuceneQuery } from "../search/parser.js";
5
+ import {
6
+ CHART_METRICS,
7
+ findChartDimension,
8
+ findChartMetric
9
+ } from "./chart-metrics.js";
10
+ import {
11
+ CHART_DAY_GRAIN_MAX_DAYS,
12
+ CHART_GRAIN_DEFAULT,
13
+ CHART_GRAINS,
14
+ CHART_ID_MAX_LENGTH,
15
+ CHART_QUERY_MAX_LENGTH,
16
+ CHART_TOP_DEFAULT,
17
+ CHART_TOP_MAX,
18
+ CHART_WINDOW_AMOUNT_MAX,
19
+ CHART_WINDOW_DEFAULT,
20
+ CHART_WINDOW_UNITS,
21
+ chartToday,
22
+ chartWindowRange
23
+ } from "./chart-spec.js";
24
+ class ChartQueryError extends Error {
25
+ kind;
26
+ /** A name to use instead, for "did you mean". */
27
+ suggestion;
28
+ constructor(message, kind, suggestion) {
29
+ super(message);
30
+ this.name = "ChartQueryError";
31
+ this.kind = kind;
32
+ this.suggestion = suggestion;
33
+ }
34
+ }
35
+ const isChartQueryError = (error) => error instanceof ChartQueryError || typeof error === "object" && error !== null && error.name === "ChartQueryError";
36
+ const KEYWORDS = ["by", "every", "over", "top", "where"];
37
+ const DURATION = /^(\d{1,4})([dwm])$/i;
38
+ const INTEGER = /^\d{1,4}$/;
39
+ const parseChartQuery = (text, options = {}) => validateChartSpec(readChartQueryText(text), options);
40
+ const readChartQueryText = (text) => {
41
+ if (text.length > CHART_QUERY_MAX_LENGTH) {
42
+ throw new ChartQueryError(
43
+ `The query is too long. The maximum is ${CHART_QUERY_MAX_LENGTH} characters.`,
44
+ "syntax"
45
+ );
46
+ }
47
+ const tokens = [...text.matchAll(/\S+/g)];
48
+ if (tokens.length === 0) {
49
+ throw new ChartQueryError(
50
+ "The query is empty. Start with a metric.",
51
+ "syntax"
52
+ );
53
+ }
54
+ const metric = tokens[0][0];
55
+ if (isKeyword(metric)) {
56
+ throw new ChartQueryError(
57
+ `The query starts with "${metric}". Start with a metric.`,
58
+ "syntax"
59
+ );
60
+ }
61
+ const spec = { metric };
62
+ const seen = /* @__PURE__ */ new Set();
63
+ let index = 1;
64
+ while (index < tokens.length) {
65
+ const word = tokens[index][0];
66
+ const keyword = word.toLowerCase();
67
+ if (!isKeyword(keyword)) {
68
+ const suggestion = closestField(keyword, KEYWORDS);
69
+ throw new ChartQueryError(
70
+ `"${word}" is not a clause.${suggestion ? ` Did you mean "${suggestion}"?` : ""} Use by, every, over, top or where.`,
71
+ "syntax",
72
+ suggestion
73
+ );
74
+ }
75
+ if (seen.has(keyword)) {
76
+ throw new ChartQueryError(
77
+ `"${keyword}" occurs more than one time.`,
78
+ "syntax"
79
+ );
80
+ }
81
+ seen.add(keyword);
82
+ if (keyword === "where") {
83
+ const start = (tokens[index].index ?? 0) + word.length;
84
+ const filter = text.slice(start).trim();
85
+ if (filter.length === 0) {
86
+ throw new ChartQueryError('"where" has no filter after it.', "syntax");
87
+ }
88
+ spec.filter = filter;
89
+ break;
90
+ }
91
+ const value = tokens[index + 1]?.[0];
92
+ if (value === void 0 || isKeyword(value.toLowerCase())) {
93
+ throw new ChartQueryError(`"${keyword}" has no value after it.`, "syntax");
94
+ }
95
+ switch (keyword) {
96
+ case "by":
97
+ spec.by = value;
98
+ break;
99
+ case "every":
100
+ spec.grain = readGrain(value);
101
+ break;
102
+ case "over":
103
+ spec.window = readDuration(value);
104
+ break;
105
+ case "top":
106
+ spec.top = readTop(value);
107
+ break;
108
+ }
109
+ index += 2;
110
+ }
111
+ return {
112
+ ...spec,
113
+ grain: spec.grain ?? CHART_GRAIN_DEFAULT,
114
+ window: spec.window ?? CHART_WINDOW_DEFAULT
115
+ };
116
+ };
117
+ const isKeyword = (word) => KEYWORDS.includes(word);
118
+ const readGrain = (value) => {
119
+ const grain = value.toLowerCase();
120
+ if (!CHART_GRAINS.includes(grain)) {
121
+ throw new ChartQueryError(
122
+ `"every ${value}" is not a bucket. Use day, week or month.`,
123
+ "bad-value"
124
+ );
125
+ }
126
+ return grain;
127
+ };
128
+ const readDuration = (value) => {
129
+ const match = DURATION.exec(value);
130
+ if (!match || Number(match[1]) === 0) {
131
+ throw new ChartQueryError(
132
+ `"over ${value}" is not a duration. Use a number and d, w or m, for example 90d.`,
133
+ "bad-value"
134
+ );
135
+ }
136
+ return {
137
+ amount: Number(match[1]),
138
+ unit: match[2].toLowerCase()
139
+ };
140
+ };
141
+ const readTop = (value) => {
142
+ if (!INTEGER.test(value)) {
143
+ throw new ChartQueryError(`"top ${value}" is not a number.`, "bad-value");
144
+ }
145
+ return Number(value);
146
+ };
147
+ const validateChartSpec = (spec, options = {}) => {
148
+ const metrics = options.metrics ?? CHART_METRICS;
149
+ const metric = findChartMetric(spec.metric, metrics);
150
+ if (!metric) {
151
+ const suggestion = closestField(
152
+ spec.metric,
153
+ metrics.map((entry) => entry.id)
154
+ );
155
+ throw new ChartQueryError(
156
+ `There is no metric "${spec.metric}".${suggestion ? ` Did you mean "${suggestion}"?` : ""}`,
157
+ "unknown-metric",
158
+ suggestion
159
+ );
160
+ }
161
+ let by;
162
+ if (spec.by !== void 0) {
163
+ const dimension = findChartDimension(metric, spec.by);
164
+ if (!dimension) {
165
+ const ids = metric.dimensions.map((entry) => entry.id);
166
+ const suggestion = closestField(spec.by, ids);
167
+ throw new ChartQueryError(
168
+ `${metric.id} has no dimension "${spec.by}". Use one of: ${ids.join(", ")}.`,
169
+ "unknown-dimension",
170
+ suggestion
171
+ );
172
+ }
173
+ by = dimension.id;
174
+ }
175
+ if (!metric.grains.includes(spec.grain)) {
176
+ throw new ChartQueryError(
177
+ `${metric.id} has no bucket "${spec.grain}". Use one of: ${metric.grains.join(", ")}.`,
178
+ "bad-value"
179
+ );
180
+ }
181
+ const today = options.today ?? chartToday();
182
+ const { days } = chartWindowRange(spec.window, spec.grain, today);
183
+ if (days > metric.maxWindowDays) {
184
+ throw new ChartQueryError(
185
+ `"over ${formatDuration(spec.window)}" reads ${days} days. ${metric.id} reads at most ${metric.maxWindowDays} days.`,
186
+ "bad-value"
187
+ );
188
+ }
189
+ if (spec.grain === "day" && days > CHART_DAY_GRAIN_MAX_DAYS) {
190
+ throw new ChartQueryError(
191
+ `"over ${formatDuration(spec.window)}" reads ${days} days. With "every day", the maximum is ${CHART_DAY_GRAIN_MAX_DAYS} days. Use "every week" or "every month".`,
192
+ "bad-value"
193
+ );
194
+ }
195
+ let top;
196
+ if (spec.top !== void 0 && by === void 0) {
197
+ throw new ChartQueryError(
198
+ '"top" needs "by". Without "by", the chart has one series.',
199
+ "syntax"
200
+ );
201
+ }
202
+ if (by !== void 0) {
203
+ top = spec.top ?? CHART_TOP_DEFAULT;
204
+ if (top < 1 || top > CHART_TOP_MAX) {
205
+ throw new ChartQueryError(
206
+ `"top ${top}" is out of range. Use 1 to ${CHART_TOP_MAX}.`,
207
+ "bad-value"
208
+ );
209
+ }
210
+ }
211
+ const filter = spec.filter?.trim() || void 0;
212
+ if (filter !== void 0) {
213
+ checkFilter(filter, metric.filters);
214
+ }
215
+ return {
216
+ metric: metric.id,
217
+ ...by !== void 0 ? { by } : {},
218
+ grain: spec.grain,
219
+ window: { amount: spec.window.amount, unit: spec.window.unit },
220
+ ...filter !== void 0 ? { filter } : {},
221
+ ...top !== void 0 ? { top } : {}
222
+ };
223
+ };
224
+ const checkFilter = (filter, fields) => {
225
+ let ast;
226
+ try {
227
+ ast = parseLuceneQuery(filter);
228
+ } catch (error) {
229
+ if (isLuceneQueryError(error)) {
230
+ throw new ChartQueryError(`In "where": ${error.message}`, "syntax");
231
+ }
232
+ throw error;
233
+ }
234
+ if (ast) {
235
+ checkFilterNode(ast, fields);
236
+ }
237
+ };
238
+ const checkFilterNode = (node, fields) => {
239
+ switch (node.kind) {
240
+ case "and":
241
+ case "or":
242
+ checkFilterNode(node.left, fields);
243
+ checkFilterNode(node.right, fields);
244
+ return;
245
+ case "not":
246
+ checkFilterNode(node.child, fields);
247
+ return;
248
+ case "range": {
249
+ const spec = filterField(node.field, fields);
250
+ if (!spec.capabilities.includes("range")) {
251
+ throw new ChartQueryError(
252
+ `"${spec.field}" does not take a range.`,
253
+ "bad-value"
254
+ );
255
+ }
256
+ return;
257
+ }
258
+ case "term": {
259
+ if (node.field === void 0) {
260
+ throw new ChartQueryError(
261
+ `"${node.value}" has no field. Write field:value, for example ${fields[0]?.example ?? "orgId:\u2026"}.`,
262
+ "syntax"
263
+ );
264
+ }
265
+ const spec = filterField(node.field, fields);
266
+ if (node.operator !== ":" && !spec.capabilities.includes("range")) {
267
+ throw new ChartQueryError(
268
+ `"${spec.field}" takes only ${spec.field}:value.`,
269
+ "bad-value"
270
+ );
271
+ }
272
+ if (node.value.startsWith("$")) {
273
+ throw new ChartQueryError(
274
+ `"${node.value}" is a dashboard variable. Dashboard variables are not available yet.`,
275
+ "bad-value"
276
+ );
277
+ }
278
+ if (spec.type === "enum" && !spec.enumValues?.some(
279
+ (value) => value.toLowerCase() === node.value.toLowerCase()
280
+ )) {
281
+ throw new ChartQueryError(
282
+ `"${spec.field}" takes one of: ${spec.enumValues?.join(", ")}.`,
283
+ "bad-value"
284
+ );
285
+ }
286
+ return;
287
+ }
288
+ }
289
+ };
290
+ const filterField = (name, fields) => {
291
+ const spec = findSearchField(fields, name);
292
+ if (!spec) {
293
+ const suggestion = closestField(
294
+ name,
295
+ fields.map((field) => field.field)
296
+ );
297
+ throw new ChartQueryError(
298
+ `There is no filter field "${name}".${suggestion ? ` Did you mean "${suggestion}"?` : ""}`,
299
+ "unknown-field",
300
+ suggestion
301
+ );
302
+ }
303
+ return spec;
304
+ };
305
+ const formatDuration = (window) => `${window.amount}${window.unit}`;
306
+ const formatChartSpec = (spec) => [
307
+ spec.metric,
308
+ ...spec.by !== void 0 ? ["by", spec.by] : [],
309
+ "every",
310
+ spec.grain,
311
+ "over",
312
+ formatDuration(spec.window),
313
+ ...spec.top !== void 0 ? ["top", String(spec.top)] : [],
314
+ ...spec.filter !== void 0 ? ["where", spec.filter] : []
315
+ ].join(" ");
316
+ const readChartSpec = (value) => {
317
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
318
+ throw new ChartQueryError("The chart query must be an object.", "syntax");
319
+ }
320
+ const record = value;
321
+ const allowed = /* @__PURE__ */ new Set(["metric", "by", "grain", "window", "filter", "top"]);
322
+ for (const key of Object.keys(record)) {
323
+ if (!allowed.has(key)) {
324
+ throw new ChartQueryError(
325
+ `The chart query has an unknown key "${key}".`,
326
+ "syntax"
327
+ );
328
+ }
329
+ }
330
+ const { metric, by, grain, window, filter, top } = record;
331
+ if (typeof metric !== "string" || metric.length === 0 || metric.length > CHART_ID_MAX_LENGTH) {
332
+ throw new ChartQueryError('"metric" must be a string.', "syntax");
333
+ }
334
+ if (by !== void 0 && (typeof by !== "string" || by.length > CHART_ID_MAX_LENGTH)) {
335
+ throw new ChartQueryError('"by" must be a string.', "syntax");
336
+ }
337
+ if (typeof grain !== "string" || !CHART_GRAINS.includes(grain)) {
338
+ throw new ChartQueryError(
339
+ `"grain" must be one of: ${CHART_GRAINS.join(", ")}.`,
340
+ "syntax"
341
+ );
342
+ }
343
+ if (typeof window !== "object" || window === null) {
344
+ throw new ChartQueryError('"window" must be an object.', "syntax");
345
+ }
346
+ const { amount, unit } = window;
347
+ if (typeof amount !== "number" || !Number.isInteger(amount) || amount < 1 || amount > CHART_WINDOW_AMOUNT_MAX || typeof unit !== "string" || !CHART_WINDOW_UNITS.includes(unit) || Object.keys(window).length !== 2) {
348
+ throw new ChartQueryError(
349
+ `"window" must be { amount, unit }, with a whole amount from 1 to ${CHART_WINDOW_AMOUNT_MAX} and a unit of d, w or m.`,
350
+ "syntax"
351
+ );
352
+ }
353
+ if (filter !== void 0 && typeof filter !== "string") {
354
+ throw new ChartQueryError('"filter" must be a string.', "syntax");
355
+ }
356
+ if (top !== void 0 && (typeof top !== "number" || !Number.isInteger(top))) {
357
+ throw new ChartQueryError('"top" must be a whole number.', "syntax");
358
+ }
359
+ return {
360
+ metric,
361
+ ...by !== void 0 ? { by } : {},
362
+ grain,
363
+ window: { amount, unit },
364
+ ...filter !== void 0 ? { filter } : {},
365
+ ...top !== void 0 ? { top } : {}
366
+ };
367
+ };
368
+ export {
369
+ ChartQueryError,
370
+ formatChartSpec,
371
+ isChartQueryError,
372
+ parseChartQuery,
373
+ readChartSpec,
374
+ validateChartSpec
375
+ };
376
+ //# sourceMappingURL=chart-query.js.map