@perses-dev/core 0.21.0 → 0.22.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 (56) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/model/dashboard.js +1 -1
  3. package/dist/cjs/model/datasource.js +1 -1
  4. package/dist/cjs/model/definitions.js +1 -1
  5. package/dist/cjs/model/display.js +1 -1
  6. package/dist/cjs/model/index.js +1 -1
  7. package/dist/cjs/model/layout.js +1 -1
  8. package/dist/cjs/model/panels.js +1 -1
  9. package/dist/cjs/model/resource.js +1 -1
  10. package/dist/cjs/model/time-series-queries.js +1 -1
  11. package/dist/cjs/model/time.js +189 -4
  12. package/dist/cjs/model/variables.js +1 -1
  13. package/dist/cjs/utils/event.js +1 -1
  14. package/dist/cjs/utils/fetch.js +1 -1
  15. package/dist/cjs/utils/index.js +1 -1
  16. package/dist/cjs/utils/memo.js +1 -1
  17. package/dist/cjs/utils/panel-refs.js +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/model/dashboard.js +1 -1
  21. package/dist/model/dashboard.js.map +1 -1
  22. package/dist/model/datasource.js +1 -1
  23. package/dist/model/datasource.js.map +1 -1
  24. package/dist/model/definitions.js +1 -1
  25. package/dist/model/definitions.js.map +1 -1
  26. package/dist/model/display.js +1 -1
  27. package/dist/model/display.js.map +1 -1
  28. package/dist/model/index.js +1 -1
  29. package/dist/model/index.js.map +1 -1
  30. package/dist/model/layout.js +1 -1
  31. package/dist/model/layout.js.map +1 -1
  32. package/dist/model/panels.js +1 -1
  33. package/dist/model/panels.js.map +1 -1
  34. package/dist/model/resource.js +1 -1
  35. package/dist/model/resource.js.map +1 -1
  36. package/dist/model/time-series-queries.js +1 -1
  37. package/dist/model/time-series-queries.js.map +1 -1
  38. package/dist/model/time.d.ts +4 -0
  39. package/dist/model/time.d.ts.map +1 -1
  40. package/dist/model/time.js +190 -4
  41. package/dist/model/time.js.map +1 -1
  42. package/dist/model/variables.d.ts +1 -1
  43. package/dist/model/variables.d.ts.map +1 -1
  44. package/dist/model/variables.js +1 -1
  45. package/dist/model/variables.js.map +1 -1
  46. package/dist/utils/event.js +1 -1
  47. package/dist/utils/event.js.map +1 -1
  48. package/dist/utils/fetch.js +1 -1
  49. package/dist/utils/fetch.js.map +1 -1
  50. package/dist/utils/index.js +1 -1
  51. package/dist/utils/index.js.map +1 -1
  52. package/dist/utils/memo.js +1 -1
  53. package/dist/utils/memo.js.map +1 -1
  54. package/dist/utils/panel-refs.js +1 -1
  55. package/dist/utils/panel-refs.js.map +1 -1
  56. package/package.json +1 -1
package/dist/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -26,6 +26,7 @@ _export(exports, {
26
26
  toAbsoluteTimeRange: ()=>toAbsoluteTimeRange,
27
27
  parseDurationString: ()=>parseDurationString,
28
28
  isDurationString: ()=>isDurationString,
29
+ roundStepInterval: ()=>roundStepInterval,
29
30
  getSuggestedStepMs: ()=>getSuggestedStepMs
30
31
  });
31
32
  const _dateFns = require("date-fns");
@@ -64,9 +65,193 @@ function isDurationString(maybeDuration) {
64
65
  if (maybeDuration === '') return false;
65
66
  return DURATION_REGEX.test(maybeDuration);
66
67
  }
68
+ const DEFAULT_STEP_MS = 15000;
69
+ const ROUNDED_STEP_INTERVALS = [
70
+ // max: 0.015s
71
+ {
72
+ maxMs: 15,
73
+ roundedStepMs: 10,
74
+ display: '0.01s'
75
+ },
76
+ // max: 0.035s
77
+ {
78
+ maxMs: 35,
79
+ roundedStepMs: 20,
80
+ display: '0.02s'
81
+ },
82
+ // max: 0.075s
83
+ {
84
+ maxMs: 75,
85
+ roundedStepMs: 50,
86
+ display: '0.05s'
87
+ },
88
+ // max: 0.15s
89
+ {
90
+ maxMs: 150,
91
+ roundedStepMs: 100,
92
+ display: '0.1s'
93
+ },
94
+ // max: 0.35s
95
+ {
96
+ maxMs: 350,
97
+ roundedStepMs: 200,
98
+ display: '0.2s'
99
+ },
100
+ // max: 0.75s
101
+ {
102
+ maxMs: 750,
103
+ roundedStepMs: 500,
104
+ display: '0.5s'
105
+ },
106
+ // max: 1.5s
107
+ {
108
+ maxMs: 1500,
109
+ roundedStepMs: 1000,
110
+ display: '1s'
111
+ },
112
+ // max: 3.5s
113
+ {
114
+ maxMs: 3500,
115
+ roundedStepMs: 2000,
116
+ display: '2s'
117
+ },
118
+ // max: 7.5s
119
+ {
120
+ maxMs: 7500,
121
+ roundedStepMs: 5000,
122
+ display: '5s'
123
+ },
124
+ // max: 12.5s
125
+ {
126
+ maxMs: 12500,
127
+ roundedStepMs: 10000,
128
+ display: '10s'
129
+ },
130
+ // max: 17.5s
131
+ {
132
+ maxMs: 17500,
133
+ roundedStepMs: 15000,
134
+ display: '15s'
135
+ },
136
+ // max: 25s
137
+ {
138
+ maxMs: 25000,
139
+ roundedStepMs: 20000,
140
+ display: '20s'
141
+ },
142
+ // max: 45s
143
+ {
144
+ maxMs: 45000,
145
+ roundedStepMs: 30000,
146
+ display: '30s'
147
+ },
148
+ // max: 1.5m
149
+ {
150
+ maxMs: 90000,
151
+ roundedStepMs: 60000,
152
+ display: '1m'
153
+ },
154
+ // max: 3.5m
155
+ {
156
+ maxMs: 210000,
157
+ roundedStepMs: 120000,
158
+ display: '2m'
159
+ },
160
+ // max: 7.5m
161
+ {
162
+ maxMs: 450000,
163
+ roundedStepMs: 300000,
164
+ display: '5m'
165
+ },
166
+ // max: 12.5m
167
+ {
168
+ maxMs: 750000,
169
+ roundedStepMs: 600000,
170
+ display: '10m'
171
+ },
172
+ // max: 12.5m
173
+ {
174
+ maxMs: 1050000,
175
+ roundedStepMs: 900000,
176
+ display: '15m'
177
+ },
178
+ // max: 25m
179
+ {
180
+ maxMs: 1500000,
181
+ roundedStepMs: 1200000,
182
+ display: '20m'
183
+ },
184
+ // max: 45m
185
+ {
186
+ maxMs: 2700000,
187
+ roundedStepMs: 1800000,
188
+ display: '30m'
189
+ },
190
+ // max: 1.5h
191
+ {
192
+ maxMs: 5400000,
193
+ roundedStepMs: 3600000,
194
+ display: '1h'
195
+ },
196
+ // max: 2.5h
197
+ {
198
+ maxMs: 9000000,
199
+ roundedStepMs: 7200000,
200
+ display: '2h'
201
+ },
202
+ // max: 4.5h
203
+ {
204
+ maxMs: 16200000,
205
+ roundedStepMs: 10800000,
206
+ display: '3h'
207
+ },
208
+ // max: 9h
209
+ {
210
+ maxMs: 32400000,
211
+ roundedStepMs: 21600000,
212
+ display: '6h'
213
+ },
214
+ // max: 1d
215
+ {
216
+ maxMs: 86400000,
217
+ roundedStepMs: 43200000,
218
+ display: '12h'
219
+ },
220
+ // max: 1w
221
+ {
222
+ maxMs: 604800000,
223
+ roundedStepMs: 86400000,
224
+ display: '1d'
225
+ },
226
+ // max: 3w
227
+ {
228
+ maxMs: 1814400000,
229
+ roundedStepMs: 604800000,
230
+ display: '1w'
231
+ },
232
+ // max: 6w
233
+ {
234
+ maxMs: 3628800000,
235
+ roundedStepMs: 2592000000,
236
+ display: '30d'
237
+ },
238
+ // max: 2y
239
+ {
240
+ maxMs: 63072000000,
241
+ roundedStepMs: 31536000000,
242
+ display: '1y'
243
+ }
244
+ ];
245
+ function roundStepInterval(stepMs) {
246
+ for (const { maxMs , roundedStepMs } of ROUNDED_STEP_INTERVALS){
247
+ if (stepMs < maxMs) {
248
+ return roundedStepMs;
249
+ }
250
+ }
251
+ return DEFAULT_STEP_MS;
252
+ }
67
253
  function getSuggestedStepMs(timeRange, width) {
68
- // TODO: Should we try to suggest more "rounded" step values based around
69
- // time increments that make sense (e.g. 15s, 30s, 1m, 5m, etc.)
70
254
  const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();
71
- return Math.floor(queryRangeMs / width);
255
+ const stepMs = Math.floor(queryRangeMs / width);
256
+ return roundStepInterval(stepMs);
72
257
  }
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './model';\nexport * from './utils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './model';\nexport * from './utils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/dashboard.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSpec } from './datasource';\nimport { LayoutDefinition } from './layout';\nimport { PanelDefinition } from './panels';\nimport { ProjectMetadata } from './resource';\nimport { DurationString } from './time';\nimport { VariableDefinition } from './variables';\nimport { Display } from './display';\n\nexport interface DashboardResource {\n kind: 'Dashboard';\n metadata: ProjectMetadata;\n spec: DashboardSpec;\n}\n\nexport interface DashboardSpec {\n display?: Display;\n datasources?: Record<string, DatasourceSpec>;\n duration: DurationString;\n variables: VariableDefinition[];\n layouts: LayoutDefinition[];\n panels: Record<string, PanelDefinition>;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAqBC"}
1
+ {"version":3,"sources":["../../src/model/dashboard.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSpec } from './datasource';\nimport { LayoutDefinition } from './layout';\nimport { PanelDefinition } from './panels';\nimport { ProjectMetadata } from './resource';\nimport { DurationString } from './time';\nimport { VariableDefinition } from './variables';\nimport { Display } from './display';\n\nexport interface DashboardResource {\n kind: 'Dashboard';\n metadata: ProjectMetadata;\n spec: DashboardSpec;\n}\n\nexport interface DashboardSpec {\n display?: Display;\n datasources?: Record<string, DatasourceSpec>;\n duration: DurationString;\n variables: VariableDefinition[];\n layouts: LayoutDefinition[];\n panels: Record<string, PanelDefinition>;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAqBC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/datasource.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { Metadata, ProjectMetadata } from './resource';\nimport { Display } from './display';\n\n/**\n * A Datasource that's available across all projects.\n */\nexport interface GlobalDatasource {\n kind: 'GlobalDatasource';\n metadata: Metadata;\n spec: DatasourceSpec;\n}\n\n/**\n * A Datasource that belongs to a project.\n */\nexport interface Datasource {\n kind: 'Datasource';\n metadata: ProjectMetadata;\n spec: DatasourceSpec;\n}\n\nexport interface DatasourceSpec<PluginSpec = UnknownSpec> {\n display?: Display;\n default: boolean;\n plugin: Definition<PluginSpec>;\n}\n\n/**\n * A selector for pointing at a specific Datasource. If name is omitted, it's assumed that you want the default\n * Datasource for the specified kind.\n */\nexport interface DatasourceSelector {\n kind: string;\n name?: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAmCC"}
1
+ {"version":3,"sources":["../../src/model/datasource.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { Metadata, ProjectMetadata } from './resource';\nimport { Display } from './display';\n\n/**\n * A Datasource that's available across all projects.\n */\nexport interface GlobalDatasource {\n kind: 'GlobalDatasource';\n metadata: Metadata;\n spec: DatasourceSpec;\n}\n\n/**\n * A Datasource that belongs to a project.\n */\nexport interface Datasource {\n kind: 'Datasource';\n metadata: ProjectMetadata;\n spec: DatasourceSpec;\n}\n\nexport interface DatasourceSpec<PluginSpec = UnknownSpec> {\n display?: Display;\n default: boolean;\n plugin: Definition<PluginSpec>;\n}\n\n/**\n * A selector for pointing at a specific Datasource. If name is omitted, it's assumed that you want the default\n * Datasource for the specified kind.\n */\nexport interface DatasourceSelector {\n kind: string;\n name?: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAmCC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/definitions.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Base type for definitions in JSON config resources.\n */\nexport interface Definition<Spec> {\n kind: string;\n spec: Spec;\n}\n\n/**\n * Type to represent specs at runtime in framework code where we don't know the spec's real type, probably because it's\n * part of a plugin.\n */\nexport type UnknownSpec = Record<string, unknown>;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;CAEC,GACD,WASkD"}
1
+ {"version":3,"sources":["../../src/model/definitions.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Base type for definitions in JSON config resources.\n */\nexport interface Definition<Spec> {\n kind: string;\n spec: Spec;\n}\n\n/**\n * Type to represent specs at runtime in framework code where we don't know the spec's real type, probably because it's\n * part of a plugin.\n */\nexport type UnknownSpec = Record<string, unknown>;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;CAEC,GACD,WASkD"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/display.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface Display {\n name: string;\n description?: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAGC"}
1
+ {"version":3,"sources":["../../src/model/display.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface Display {\n name: string;\n description?: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAGC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './layout';\nexport * from './panels';\nexport * from './resource';\nexport * from './time';\nexport * from './time-series-queries';\nexport * from './variables';\nexport * from './display';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './layout';\nexport * from './panels';\nexport * from './resource';\nexport * from './time';\nexport * from './time-series-queries';\nexport * from './variables';\nexport * from './display';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/layout.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelRef } from './panels';\n\nexport type LayoutDefinition = GridDefinition;\n\nexport interface GridDefinition {\n kind: 'Grid';\n spec: {\n display?: {\n title: string;\n collapse?: {\n open: boolean;\n };\n };\n items: GridItemDefinition[];\n };\n}\n\nexport interface GridItemDefinition {\n x: number;\n y: number;\n width: number;\n height: number;\n content: PanelRef;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAuBC"}
1
+ {"version":3,"sources":["../../src/model/layout.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelRef } from './panels';\n\nexport type LayoutDefinition = GridDefinition;\n\nexport interface GridDefinition {\n kind: 'Grid';\n spec: {\n display?: {\n title: string;\n collapse?: {\n open: boolean;\n };\n };\n items: GridItemDefinition[];\n };\n}\n\nexport interface GridItemDefinition {\n x: number;\n y: number;\n width: number;\n height: number;\n content: PanelRef;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAuBC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/panels.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { Display } from './display';\n\nexport interface PanelDefinition<PluginSpec = UnknownSpec> extends Definition<PanelSpec<PluginSpec>> {\n kind: 'Panel';\n}\n\nexport interface PanelSpec<PluginSpec> {\n display: Display;\n plugin: Definition<PluginSpec>;\n}\n\n/**\n * A reference to a panel defined in the DashboardSpec.\n */\nexport interface PanelRef {\n $ref: `#/spec/panels/${string}`;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAiBC"}
1
+ {"version":3,"sources":["../../src/model/panels.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { Display } from './display';\n\nexport interface PanelDefinition<PluginSpec = UnknownSpec> extends Definition<PanelSpec<PluginSpec>> {\n kind: 'Panel';\n}\n\nexport interface PanelSpec<PluginSpec> {\n display: Display;\n plugin: Definition<PluginSpec>;\n}\n\n/**\n * A reference to a panel defined in the DashboardSpec.\n */\nexport interface PanelRef {\n $ref: `#/spec/panels/${string}`;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAiBC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/resource.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface Metadata {\n name: string;\n created_at: string;\n updated_at: string;\n version: number;\n}\n\nexport interface ProjectMetadata extends Metadata {\n project: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WASC"}
1
+ {"version":3,"sources":["../../src/model/resource.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface Metadata {\n name: string;\n created_at: string;\n updated_at: string;\n version: number;\n}\n\nexport interface ProjectMetadata extends Metadata {\n project: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WASC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/time-series-queries.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\n\nexport interface TimeSeriesQueryDefinition<PluginSpec = UnknownSpec>\n extends Definition<TimeSeriesQuerySpec<PluginSpec>> {\n kind: 'TimeSeriesQuery';\n}\n\nexport interface TimeSeriesQuerySpec<PluginSpec> {\n plugin: Definition<PluginSpec>;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WASC"}
1
+ {"version":3,"sources":["../../src/model/time-series-queries.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\n\nexport interface TimeSeriesQueryDefinition<PluginSpec = UnknownSpec>\n extends Definition<TimeSeriesQuerySpec<PluginSpec>> {\n kind: 'TimeSeriesQuery';\n}\n\nexport interface TimeSeriesQuerySpec<PluginSpec> {\n plugin: Definition<PluginSpec>;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WASC"}
@@ -39,6 +39,10 @@ export declare function parseDurationString(durationString: string): Duration;
39
39
  * Returns true if the given string is a valid DurationString.
40
40
  */
41
41
  export declare function isDurationString(maybeDuration: string): maybeDuration is DurationString;
42
+ /**
43
+ * Round interval to clearer increments
44
+ */
45
+ export declare function roundStepInterval(stepMs: number): number;
42
46
  /**
43
47
  * Gets a suggested step/interval size for a time range based on the width of a visual component.
44
48
  */
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/model/time.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAO,MAAM,UAAU,CAAC;AAEzC,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,oBAAY,cAAc,GAAG,MAAM,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,IAAI,CAAC;IACZ,GAAG,EAAE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,iBAAiB;IAEhC,GA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AAE,GACvG,qBAAqB,GACrB,EAAE,GAAG,qBAAqB,GAAG,EAAE,GAAG,0BAA0B,GAAG,EAAE,EAAE,EACvE,EAAE,CACH,CAAC;AAIF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,QAAQ,CAepE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,IAAI,cAAc,CAGvF;AAiED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,UAO/C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,UAI7E"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -57,13 +57,199 @@ const DURATION_REGEX = /^(?:(\d+)y)?(?:(\d+)w)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?
57
57
  if (maybeDuration === '') return false;
58
58
  return DURATION_REGEX.test(maybeDuration);
59
59
  }
60
+ const DEFAULT_STEP_MS = 15000;
61
+ const ROUNDED_STEP_INTERVALS = [
62
+ // max: 0.015s
63
+ {
64
+ maxMs: 15,
65
+ roundedStepMs: 10,
66
+ display: '0.01s'
67
+ },
68
+ // max: 0.035s
69
+ {
70
+ maxMs: 35,
71
+ roundedStepMs: 20,
72
+ display: '0.02s'
73
+ },
74
+ // max: 0.075s
75
+ {
76
+ maxMs: 75,
77
+ roundedStepMs: 50,
78
+ display: '0.05s'
79
+ },
80
+ // max: 0.15s
81
+ {
82
+ maxMs: 150,
83
+ roundedStepMs: 100,
84
+ display: '0.1s'
85
+ },
86
+ // max: 0.35s
87
+ {
88
+ maxMs: 350,
89
+ roundedStepMs: 200,
90
+ display: '0.2s'
91
+ },
92
+ // max: 0.75s
93
+ {
94
+ maxMs: 750,
95
+ roundedStepMs: 500,
96
+ display: '0.5s'
97
+ },
98
+ // max: 1.5s
99
+ {
100
+ maxMs: 1500,
101
+ roundedStepMs: 1000,
102
+ display: '1s'
103
+ },
104
+ // max: 3.5s
105
+ {
106
+ maxMs: 3500,
107
+ roundedStepMs: 2000,
108
+ display: '2s'
109
+ },
110
+ // max: 7.5s
111
+ {
112
+ maxMs: 7500,
113
+ roundedStepMs: 5000,
114
+ display: '5s'
115
+ },
116
+ // max: 12.5s
117
+ {
118
+ maxMs: 12500,
119
+ roundedStepMs: 10000,
120
+ display: '10s'
121
+ },
122
+ // max: 17.5s
123
+ {
124
+ maxMs: 17500,
125
+ roundedStepMs: 15000,
126
+ display: '15s'
127
+ },
128
+ // max: 25s
129
+ {
130
+ maxMs: 25000,
131
+ roundedStepMs: 20000,
132
+ display: '20s'
133
+ },
134
+ // max: 45s
135
+ {
136
+ maxMs: 45000,
137
+ roundedStepMs: 30000,
138
+ display: '30s'
139
+ },
140
+ // max: 1.5m
141
+ {
142
+ maxMs: 90000,
143
+ roundedStepMs: 60000,
144
+ display: '1m'
145
+ },
146
+ // max: 3.5m
147
+ {
148
+ maxMs: 210000,
149
+ roundedStepMs: 120000,
150
+ display: '2m'
151
+ },
152
+ // max: 7.5m
153
+ {
154
+ maxMs: 450000,
155
+ roundedStepMs: 300000,
156
+ display: '5m'
157
+ },
158
+ // max: 12.5m
159
+ {
160
+ maxMs: 750000,
161
+ roundedStepMs: 600000,
162
+ display: '10m'
163
+ },
164
+ // max: 12.5m
165
+ {
166
+ maxMs: 1050000,
167
+ roundedStepMs: 900000,
168
+ display: '15m'
169
+ },
170
+ // max: 25m
171
+ {
172
+ maxMs: 1500000,
173
+ roundedStepMs: 1200000,
174
+ display: '20m'
175
+ },
176
+ // max: 45m
177
+ {
178
+ maxMs: 2700000,
179
+ roundedStepMs: 1800000,
180
+ display: '30m'
181
+ },
182
+ // max: 1.5h
183
+ {
184
+ maxMs: 5400000,
185
+ roundedStepMs: 3600000,
186
+ display: '1h'
187
+ },
188
+ // max: 2.5h
189
+ {
190
+ maxMs: 9000000,
191
+ roundedStepMs: 7200000,
192
+ display: '2h'
193
+ },
194
+ // max: 4.5h
195
+ {
196
+ maxMs: 16200000,
197
+ roundedStepMs: 10800000,
198
+ display: '3h'
199
+ },
200
+ // max: 9h
201
+ {
202
+ maxMs: 32400000,
203
+ roundedStepMs: 21600000,
204
+ display: '6h'
205
+ },
206
+ // max: 1d
207
+ {
208
+ maxMs: 86400000,
209
+ roundedStepMs: 43200000,
210
+ display: '12h'
211
+ },
212
+ // max: 1w
213
+ {
214
+ maxMs: 604800000,
215
+ roundedStepMs: 86400000,
216
+ display: '1d'
217
+ },
218
+ // max: 3w
219
+ {
220
+ maxMs: 1814400000,
221
+ roundedStepMs: 604800000,
222
+ display: '1w'
223
+ },
224
+ // max: 6w
225
+ {
226
+ maxMs: 3628800000,
227
+ roundedStepMs: 2592000000,
228
+ display: '30d'
229
+ },
230
+ // max: 2y
231
+ {
232
+ maxMs: 63072000000,
233
+ roundedStepMs: 31536000000,
234
+ display: '1y'
235
+ }
236
+ ];
237
+ /**
238
+ * Round interval to clearer increments
239
+ */ export function roundStepInterval(stepMs) {
240
+ for (const { maxMs , roundedStepMs } of ROUNDED_STEP_INTERVALS){
241
+ if (stepMs < maxMs) {
242
+ return roundedStepMs;
243
+ }
244
+ }
245
+ return DEFAULT_STEP_MS;
246
+ }
60
247
  /**
61
248
  * Gets a suggested step/interval size for a time range based on the width of a visual component.
62
249
  */ export function getSuggestedStepMs(timeRange, width) {
63
- // TODO: Should we try to suggest more "rounded" step values based around
64
- // time increments that make sense (e.g. 15s, 30s, 1m, 5m, etc.)
65
250
  const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();
66
- return Math.floor(queryRangeMs / width);
251
+ const stepMs = Math.floor(queryRangeMs / width);
252
+ return roundStepInterval(stepMs);
67
253
  }
68
254
 
69
255
  //# sourceMappingURL=time.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/time.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Duration, sub } from 'date-fns';\n\nexport type UnixTimeMs = number;\n\nexport type DateTimeFormat = number | string;\n\nexport interface AbsoluteTimeRange {\n start: Date;\n end: Date;\n}\n\nexport interface RelativeTimeRange {\n // End date or undefined if relative to the current Date\n end?: Date;\n pastDuration: DurationString;\n}\n\nexport type TimeRangeValue = AbsoluteTimeRange | RelativeTimeRange;\n\n/**\n * Determine whether a given time range is relative\n */\nexport function isRelativeTimeRange(timeRange: TimeRangeValue): timeRange is RelativeTimeRange {\n return (timeRange as RelativeTimeRange).pastDuration !== undefined;\n}\n\n/**\n * Determine whether a given time range is absolute\n */\nexport function isAbsoluteTimeRange(timeRange: TimeRangeValue): timeRange is AbsoluteTimeRange {\n return (timeRange as AbsoluteTimeRange).start !== undefined && (timeRange as AbsoluteTimeRange).end !== undefined;\n}\n\n/**\n * Returns an absolute time range from a RelativeTimeRange.\n */\nexport function toAbsoluteTimeRange(timeRange: RelativeTimeRange): AbsoluteTimeRange {\n const end = timeRange.end ?? new Date();\n\n return {\n start: sub(end, parseDurationString(timeRange.pastDuration)),\n end,\n };\n}\n\ntype MillisecondsDurationString = `${number}ms`;\ntype SecondsDurationString = `${number}s`;\ntype MinutesDurationString = `${number}m`;\ntype HoursDurationString = `${number}h`;\ntype DaysDurationString = `${number}d`;\ntype WeeksDurationString = `${number}w`;\ntype YearsDurationString = `${number}y`;\n\nexport type DurationString = Exclude<\n `${YearsDurationString | ''}${WeeksDurationString | ''}${DaysDurationString | ''}${HoursDurationString | ''}${\n | MinutesDurationString\n | ''}${SecondsDurationString | ''}${MillisecondsDurationString | ''}`,\n ''\n>;\n\nconst DURATION_REGEX = /^(?:(\\d+)y)?(?:(\\d+)w)?(?:(\\d+)d)?(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?(?:(\\d+)ms)?$/;\n\n/**\n * Parses a DurationString into a Duration object with numeric values that can\n * be used to do Date math. Throws if not a valid duration string.\n */\nexport function parseDurationString(durationString: string): Duration {\n const matches = DURATION_REGEX.exec(durationString);\n if (matches === null) {\n throw new Error(`Invalid duration string '${durationString}'`);\n }\n\n return {\n years: parseInt(matches[1] ?? '0'),\n months: 0,\n weeks: parseInt(matches[2] ?? '0'),\n days: parseInt(matches[3] ?? '0'),\n hours: parseInt(matches[4] ?? '0'),\n minutes: parseInt(matches[5] ?? '0'),\n seconds: parseInt(matches[6] ?? '0') + parseInt(matches[7] ?? '0') / 1000,\n };\n}\n\n/**\n * Returns true if the given string is a valid DurationString.\n */\nexport function isDurationString(maybeDuration: string): maybeDuration is DurationString {\n if (maybeDuration === '') return false;\n return DURATION_REGEX.test(maybeDuration);\n}\n\n/**\n * Gets a suggested step/interval size for a time range based on the width of a visual component.\n */\nexport function getSuggestedStepMs(timeRange: AbsoluteTimeRange, width: number) {\n // TODO: Should we try to suggest more \"rounded\" step values based around\n // time increments that make sense (e.g. 15s, 30s, 1m, 5m, etc.)\n const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();\n return Math.floor(queryRangeMs / width);\n}\n"],"names":["sub","isRelativeTimeRange","timeRange","pastDuration","undefined","isAbsoluteTimeRange","start","end","toAbsoluteTimeRange","Date","parseDurationString","DURATION_REGEX","durationString","matches","exec","Error","years","parseInt","months","weeks","days","hours","minutes","seconds","isDurationString","maybeDuration","test","getSuggestedStepMs","width","queryRangeMs","valueOf","Math","floor"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0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AE,GAAG5B,SAAS,CAACI,KAAK,CAACwB,OAAO,EAAE,AAAC;IACzE,OAAOC,IAAI,CAACC,KAAK,CAACH,YAAY,GAAGD,KAAK,CAAC,CAAC;AAC1C,CAAC"}
1
+ {"version":3,"sources":["../../src/model/time.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Duration, sub } from 'date-fns';\n\nexport type UnixTimeMs = number;\n\nexport type DateTimeFormat = number | string;\n\nexport interface AbsoluteTimeRange {\n start: Date;\n end: Date;\n}\n\nexport interface RelativeTimeRange {\n // End date or undefined if relative to the current Date\n end?: Date;\n pastDuration: DurationString;\n}\n\nexport type TimeRangeValue = AbsoluteTimeRange | RelativeTimeRange;\n\n/**\n * Determine whether a given time range is relative\n */\nexport function isRelativeTimeRange(timeRange: TimeRangeValue): timeRange is RelativeTimeRange {\n return (timeRange as RelativeTimeRange).pastDuration !== undefined;\n}\n\n/**\n * Determine whether a given time range is absolute\n */\nexport function isAbsoluteTimeRange(timeRange: TimeRangeValue): timeRange is AbsoluteTimeRange {\n return (timeRange as AbsoluteTimeRange).start !== undefined && (timeRange as AbsoluteTimeRange).end !== undefined;\n}\n\n/**\n * Returns an absolute time range from a RelativeTimeRange.\n */\nexport function toAbsoluteTimeRange(timeRange: RelativeTimeRange): AbsoluteTimeRange {\n const end = timeRange.end ?? new Date();\n\n return {\n start: sub(end, parseDurationString(timeRange.pastDuration)),\n end,\n };\n}\n\ntype MillisecondsDurationString = `${number}ms`;\ntype SecondsDurationString = `${number}s`;\ntype MinutesDurationString = `${number}m`;\ntype HoursDurationString = `${number}h`;\ntype DaysDurationString = `${number}d`;\ntype WeeksDurationString = `${number}w`;\ntype YearsDurationString = `${number}y`;\n\nexport type DurationString = Exclude<\n `${YearsDurationString | ''}${WeeksDurationString | ''}${DaysDurationString | ''}${HoursDurationString | ''}${\n | MinutesDurationString\n | ''}${SecondsDurationString | ''}${MillisecondsDurationString | ''}`,\n ''\n>;\n\nconst DURATION_REGEX = /^(?:(\\d+)y)?(?:(\\d+)w)?(?:(\\d+)d)?(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?(?:(\\d+)ms)?$/;\n\n/**\n * Parses a DurationString into a Duration object with numeric values that can\n * be used to do Date math. Throws if not a valid duration string.\n */\nexport function parseDurationString(durationString: string): Duration {\n const matches = DURATION_REGEX.exec(durationString);\n if (matches === null) {\n throw new Error(`Invalid duration string '${durationString}'`);\n }\n\n return {\n years: parseInt(matches[1] ?? '0'),\n months: 0,\n weeks: parseInt(matches[2] ?? '0'),\n days: parseInt(matches[3] ?? '0'),\n hours: parseInt(matches[4] ?? '0'),\n minutes: parseInt(matches[5] ?? '0'),\n seconds: parseInt(matches[6] ?? '0') + parseInt(matches[7] ?? '0') / 1000,\n };\n}\n\n/**\n * Returns true if the given string is a valid DurationString.\n */\nexport function isDurationString(maybeDuration: string): maybeDuration is DurationString {\n if (maybeDuration === '') return false;\n return DURATION_REGEX.test(maybeDuration);\n}\n\nconst DEFAULT_STEP_MS = 15000;\n\nconst ROUNDED_STEP_INTERVALS = [\n // max: 0.015s\n { maxMs: 15, roundedStepMs: 10, display: '0.01s' },\n // max: 0.035s\n { maxMs: 35, roundedStepMs: 20, display: '0.02s' },\n // max: 0.075s\n { maxMs: 75, roundedStepMs: 50, display: '0.05s' },\n // max: 0.15s\n { maxMs: 150, roundedStepMs: 100, display: '0.1s' },\n // max: 0.35s\n { maxMs: 350, roundedStepMs: 200, display: '0.2s' },\n // max: 0.75s\n { maxMs: 750, roundedStepMs: 500, display: '0.5s' },\n // max: 1.5s\n { maxMs: 1500, roundedStepMs: 1000, display: '1s' },\n // max: 3.5s\n { maxMs: 3500, roundedStepMs: 2000, display: '2s' },\n // max: 7.5s\n { maxMs: 7500, roundedStepMs: 5000, display: '5s' },\n // max: 12.5s\n { maxMs: 12500, roundedStepMs: 10000, display: '10s' },\n // max: 17.5s\n { maxMs: 17500, roundedStepMs: 15000, display: '15s' },\n // max: 25s\n { maxMs: 25000, roundedStepMs: 20000, display: '20s' },\n // max: 45s\n { maxMs: 45000, roundedStepMs: 30000, display: '30s' },\n // max: 1.5m\n { maxMs: 90000, roundedStepMs: 60000, display: '1m' },\n // max: 3.5m\n { maxMs: 210000, roundedStepMs: 120000, display: '2m' },\n // max: 7.5m\n { maxMs: 450000, roundedStepMs: 300000, display: '5m' },\n // max: 12.5m\n { maxMs: 750000, roundedStepMs: 600000, display: '10m' },\n // max: 12.5m\n { maxMs: 1050000, roundedStepMs: 900000, display: '15m' },\n // max: 25m\n { maxMs: 1500000, roundedStepMs: 1200000, display: '20m' },\n // max: 45m\n { maxMs: 2700000, roundedStepMs: 1800000, display: '30m' },\n // max: 1.5h\n { maxMs: 5400000, roundedStepMs: 3600000, display: '1h' },\n // max: 2.5h\n { maxMs: 9000000, roundedStepMs: 7200000, display: '2h' },\n // max: 4.5h\n { maxMs: 16200000, roundedStepMs: 10800000, display: '3h' },\n // max: 9h\n { maxMs: 32400000, roundedStepMs: 21600000, display: '6h' },\n // max: 1d\n { maxMs: 86400000, roundedStepMs: 43200000, display: '12h' },\n // max: 1w\n { maxMs: 604800000, roundedStepMs: 86400000, display: '1d' },\n // max: 3w\n { maxMs: 1814400000, roundedStepMs: 604800000, display: '1w' },\n // max: 6w\n { maxMs: 3628800000, roundedStepMs: 2592000000, display: '30d' },\n // max: 2y\n { maxMs: 63072000000, roundedStepMs: 31536000000, display: '1y' },\n];\n\n/**\n * Round interval to clearer increments\n */\nexport function roundStepInterval(stepMs: number) {\n for (const { maxMs, roundedStepMs } of ROUNDED_STEP_INTERVALS) {\n if (stepMs < maxMs) {\n return roundedStepMs;\n }\n }\n return DEFAULT_STEP_MS;\n}\n\n/**\n * Gets a suggested step/interval size for a time range based on the width of a visual component.\n */\nexport function getSuggestedStepMs(timeRange: AbsoluteTimeRange, width: number) {\n const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();\n const stepMs = Math.floor(queryRangeMs / width);\n return roundStepInterval(stepMs);\n}\n"],"names":["sub","isRelativeTimeRange","timeRange","pastDuration","undefined","isAbsoluteTimeRange","start","end","toAbsoluteTimeRange","Date","parseDurationString","DURATION_REGEX","durationString","matches","exec","Error","years","parseInt","months","weeks","days","hours","minutes","seconds","isDurationString","maybeDuration","test","DEFAULT_STEP_MS","ROUNDED_STEP_INTERVALS","maxMs","roundedStepMs","display","roundStepInterval","stepMs","getSuggestedStepMs","width","queryRangeMs","valueOf","Math","floor"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAmBA,GAAG,QAAQ,UAAU,CAAC;AAmBzC;;CAEC,GACD,OAAO,SAASC,mBAAmB,CAACC,SAAyB,EAAkC;IAC7F,OAAO,AAACA,SAAS,CAAuBC,YAAY,KAAKC,SAAS,CAAC;AACrE,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,mBAAmB,CAACH,SAAyB,EAAkC;IAC7F,OAAO,AAACA,SAAS,CAAuBI,KAAK,KAAKF,SAAS,IAAI,AAACF,SAAS,CAAuBK,GAAG,KAAKH,SAAS,CAAC;AACpH,CAAC;AAED;;CAEC,GACD,OAAO,SAASI,mBAAmB,CAACN,SAA4B,EAAqB;QACvEA,IAAa;IAAzB,MAAMK,GAAG,GAAGL,CAAAA,IAAa,GAAbA,SAAS,CAACK,GAAG,cAAbL,IAAa,cAAbA,IAAa,GAAI,IAAIO,IAAI,EAAE,A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A4B,EAAEiC,KAAa,EAAE;IAC9E,MAAMC,YAAY,GAAGlC,SAAS,CAACK,GAAG,CAAC8B,OAAO,EAAE,GAAGnC,SAAS,CAACI,KAAK,CAAC+B,OAAO,EAAE,AAAC;IACzE,MAAMJ,MAAM,GAAGK,IAAI,CAACC,KAAK,CAACH,YAAY,GAAGD,KAAK,CAAC,AAAC;IAChD,OAAOH,iBAAiB,CAACC,MAAM,CAAC,CAAC;AACnC,CAAC"}
@@ -7,7 +7,6 @@ interface VariableSpec {
7
7
  display?: Display & {
8
8
  hidden?: boolean;
9
9
  };
10
- default_value?: VariableValue;
11
10
  }
12
11
  export interface TextVariableDefinition extends Definition<TextVariableSpec> {
13
12
  kind: 'TextVariable';
@@ -19,6 +18,7 @@ export interface ListVariableDefinition<PluginSpec = UnknownSpec> extends Defini
19
18
  kind: 'ListVariable';
20
19
  }
21
20
  export interface ListVariableSpec<PluginSpec> extends VariableSpec {
21
+ default_value?: VariableValue;
22
22
  allow_multiple?: boolean;
23
23
  allow_all_value?: boolean;
24
24
  custom_all_value?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/model/variables.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,oBAAY,aAAa,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;AAErD,UAAU,YAAY;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,GAAG;QAClB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,MAAM,WAAW,sBAAuB,SAAQ,UAAU,CAAC,gBAAgB,CAAC;IAC1E,IAAI,EAAE,cAAc,CAAC;CACtB;A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AC;IAChH,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB,CAAC,UAAU,CAAE,SAAQ,YAAY;IAChE,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAChC;AAED,oBAAY,kBAAkB,GAAG,sBAAsB,GAAG,sBAAsB,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/variables.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { Display } from './display';\n\nexport type VariableName = string;\n\nexport type VariableValue = string | string[] | null;\n\ninterface VariableSpec {\n name: VariableName;\n display?: Display & {\n hidden?: boolean;\n };\n default_value?: VariableValue;\n}\n\nexport interface TextVariableDefinition extends Definition<TextVariableSpec> {\n kind: 'TextVariable';\n}\n\nexport interface TextVariableSpec extends VariableSpec {\n value: string;\n}\n\nexport interface ListVariableDefinition<PluginSpec = UnknownSpec> extends Definition<ListVariableSpec<PluginSpec>> {\n kind: 'ListVariable';\n}\n\nexport interface ListVariableSpec<PluginSpec> extends VariableSpec {\n allow_multiple?: boolean;\n allow_all_value?: boolean;\n custom_all_value?: string;\n capturing_regexp?: string;\n plugin: Definition<PluginSpec>;\n}\n\nexport type VariableDefinition = TextVariableDefinition | ListVariableDefinition;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAmCiF"}
1
+ {"version":3,"sources":["../../src/model/variables.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { Display } from './display';\n\nexport type VariableName = string;\n\nexport type VariableValue = string | string[] | null;\n\ninterface VariableSpec {\n name: VariableName;\n display?: Display & {\n hidden?: boolean;\n };\n}\n\nexport interface TextVariableDefinition extends Definition<TextVariableSpec> {\n kind: 'TextVariable';\n}\n\nexport interface TextVariableSpec extends VariableSpec {\n value: string;\n}\n\nexport interface ListVariableDefinition<PluginSpec = UnknownSpec> extends Definition<ListVariableSpec<PluginSpec>> {\n kind: 'ListVariable';\n}\n\nexport interface ListVariableSpec<PluginSpec> extends VariableSpec {\n default_value?: VariableValue;\n allow_multiple?: boolean;\n allow_all_value?: boolean;\n custom_all_value?: string;\n capturing_regexp?: string;\n plugin: Definition<PluginSpec>;\n}\n\nexport type VariableDefinition = TextVariableDefinition | ListVariableDefinition;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAmCiF"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/event.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useRef, useLayoutEffect, useCallback } from 'react';\n\n/**\n * A (temporary) userland implementation of `useEvent` from this React RFC: https://github.com/reactjs/rfcs/pull/220.\n *\n * Typically useful for getting a stable reference to an \"event\" function (i.e. one that isn't called during render\n * but is called later in a useEffect or event handler) that accesses state or props.\n */\nexport function useEvent<T extends unknown[], U>(handler: (...args: T) => U): (...args: T) => U {\n const handlerRef = useRef(handler);\n useLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return useCallback((...args) => handlerRef.current(...args), []);\n}\n"],"names":["useRef","useLayoutEffect","useCallback","useEvent","handler","handlerRef","current","args"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,EAAEC,eAAe,EAAEC,WAAW,QAAQ,OAAO,CAAC;AAE7D;;;;;CAKC,GACD,OAAO,SAASC,QAAQ,CAAyBC,OAA0B,EAAqB;IAC9F,MAAMC,UAAU,GAAGL,MAAM,CAACI,OAAO,CAAC,AAAC;IACnCH,eAAe,CAAC,IAAM;QACpBI,UAAU,CAACC,OAAO,GAAGF,OAAO,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,OAAOF,WAAW,CAAC,CAAIK,GAAAA,IAAI,GAAKF,UAAU,CAACC,OAAO,IAAIC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/event.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useRef, useLayoutEffect, useCallback } from 'react';\n\n/**\n * A (temporary) userland implementation of `useEvent` from this React RFC: https://github.com/reactjs/rfcs/pull/220.\n *\n * Typically useful for getting a stable reference to an \"event\" function (i.e. one that isn't called during render\n * but is called later in a useEffect or event handler) that accesses state or props.\n */\nexport function useEvent<T extends unknown[], U>(handler: (...args: T) => U): (...args: T) => U {\n const handlerRef = useRef(handler);\n useLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return useCallback((...args) => handlerRef.current(...args), []);\n}\n"],"names":["useRef","useLayoutEffect","useCallback","useEvent","handler","handlerRef","current","args"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,EAAEC,eAAe,EAAEC,WAAW,QAAQ,OAAO,CAAC;AAE7D;;;;;CAKC,GACD,OAAO,SAASC,QAAQ,CAAyBC,OAA0B,EAAqB;IAC9F,MAAMC,UAAU,GAAGL,MAAM,CAACI,OAAO,CAAC,AAAC;IACnCH,eAAe,CAAC,IAAM;QACpBI,UAAU,CAACC,OAAO,GAAGF,OAAO,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,OAAOF,WAAW,CAAC,CAAIK,GAAAA,IAAI,GAAKF,UAAU,CAACC,OAAO,IAAIC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/fetch.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Calls `global.fetch`, but throws a `FetchError` for non-200 responses.\n */\nexport async function fetch(...args: Parameters<typeof global.fetch>) {\n const response = await global.fetch(...args);\n if (response.ok === false) {\n throw new FetchError(response);\n }\n return response;\n}\n\n/**\n * Calls `global.fetch` and throws a `FetchError` on non-200 responses, but also\n * decodes the response body as JSON, casting it to type `T`. Returns the\n * decoded body.\n */\nexport async function fetchJson<T>(...args: Parameters<typeof global.fetch>) {\n const response = await fetch(...args);\n const json: T = await response.json();\n return json;\n}\n\n/**\n * Error thrown when fetch returns a non-200 response.\n */\nexport class FetchError extends Error {\n constructor(readonly response: Response) {\n super(`${response.status} ${response.statusText}`);\n Object.setPrototypeOf(this, FetchError.prototype);\n }\n}\n"],"names":["fetch","args","response","global","ok","FetchError","fetchJson","json","Error","constructor","status","statusText","Object","setPrototypeOf","prototype"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;CAEC,GACD,OAAO,eAAeA,KAAK,CAAC,GAAGC,IAAI,AAAiC,EAAE;IACpE,MAAMC,QAAQ,GAAG,MAAMC,MAAM,CAACH,KAAK,IAAIC,IAAI,CAAC,AAAC;IAC7C,IAAIC,QAAQ,CAACE,EAAE,KAAK,KAAK,EAAE;QACzB,MAAM,IAAIC,UAAU,CAACH,QAAQ,CAAC,CAAC;IACjC,CAAC;IACD,OAAOA,QAAQ,CAAC;AAClB,CAAC;AAED;;;;CAIC,GACD,OAAO,eAAeI,SAAS,CAAI,GAAGL,IAAI,AAAiC,EAAE;IAC3E,MAAMC,QAAQ,GAAG,MAAMF,KAAK,IAAIC,IAAI,CAAC,AAAC;IACtC,MAAMM,IAAI,GAAM,MAAML,QAAQ,CAACK,IAAI,EAAE,AAAC;IACtC,OAAOA,IAAI,CAAC;AACd,CAAC;AAED;;CAEC,GACD,OAAO,MAAMF,UAAU,SAASG,KAAK;IACnCC,YAAqBP,QAAkB,CAAE;QACvC,KAAK,CAAC,CAAC,EAAEA,QAAQ,CAACQ,MAAM,CAAC,CAAC,EAAER,QAAQ,CAACS,UAAU,CAAC,CAAC,CAAC,CAAC;QADhCT,gBAAAA,QAAkB,CAAA;QAErCU,MAAM,CAACC,cAAc,CAAC,IAAI,EAAER,UAAU,CAACS,SAAS,CAAC,CAAC;IACpD;CACD"}
1
+ {"version":3,"sources":["../../src/utils/fetch.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Calls `global.fetch`, but throws a `FetchError` for non-200 responses.\n */\nexport async function fetch(...args: Parameters<typeof global.fetch>) {\n const response = await global.fetch(...args);\n if (response.ok === false) {\n throw new FetchError(response);\n }\n return response;\n}\n\n/**\n * Calls `global.fetch` and throws a `FetchError` on non-200 responses, but also\n * decodes the response body as JSON, casting it to type `T`. Returns the\n * decoded body.\n */\nexport async function fetchJson<T>(...args: Parameters<typeof global.fetch>) {\n const response = await fetch(...args);\n const json: T = await response.json();\n return json;\n}\n\n/**\n * Error thrown when fetch returns a non-200 response.\n */\nexport class FetchError extends Error {\n constructor(readonly response: Response) {\n super(`${response.status} ${response.statusText}`);\n Object.setPrototypeOf(this, FetchError.prototype);\n }\n}\n"],"names":["fetch","args","response","global","ok","FetchError","fetchJson","json","Error","constructor","status","statusText","Object","setPrototypeOf","prototype"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;CAEC,GACD,OAAO,eAAeA,KAAK,CAAC,GAAGC,IAAI,AAAiC,EAAE;IACpE,MAAMC,QAAQ,GAAG,MAAMC,MAAM,CAACH,KAAK,IAAIC,IAAI,CAAC,AAAC;IAC7C,IAAIC,QAAQ,CAACE,EAAE,KAAK,KAAK,EAAE;QACzB,MAAM,IAAIC,UAAU,CAACH,QAAQ,CAAC,CAAC;IACjC,CAAC;IACD,OAAOA,QAAQ,CAAC;AAClB,CAAC;AAED;;;;CAIC,GACD,OAAO,eAAeI,SAAS,CAAI,GAAGL,IAAI,AAAiC,EAAE;IAC3E,MAAMC,QAAQ,GAAG,MAAMF,KAAK,IAAIC,IAAI,CAAC,AAAC;IACtC,MAAMM,IAAI,GAAM,MAAML,QAAQ,CAACK,IAAI,EAAE,AAAC;IACtC,OAAOA,IAAI,CAAC;AACd,CAAC;AAED;;CAEC,GACD,OAAO,MAAMF,UAAU,SAASG,KAAK;IACnCC,YAAqBP,QAAkB,CAAE;QACvC,KAAK,CAAC,CAAC,EAAEA,QAAQ,CAACQ,MAAM,CAAC,CAAC,EAAER,QAAQ,CAACS,UAAU,CAAC,CAAC,CAAC,CAAC;QADhCT,gBAAAA,QAAkB,CAAA;QAErCU,MAAM,CAACC,cAAc,CAAC,IAAI,EAAER,UAAU,CAACS,SAAS,CAAC,CAAC;IACpD;CACD"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './event';\nexport * from './fetch';\nexport * from './memo';\nexport * from './panel-refs';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './event';\nexport * from './fetch';\nexport * from './memo';\nexport * from './panel-refs';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/memo.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useRef, DependencyList } from 'react';\nimport { isEqual } from 'lodash-es';\n\ntype MemoRef<T> = {\n value: T;\n deps: DependencyList;\n};\n\n/**\n * Like React's useMemo, but guarantees the value will only be recalulated if\n * a dependency changes. Uses strict equality (===) for comparison. (React's\n * useMemo does not offer this guarantee, it's only a performance optimization).\n */\nexport function useMemoized<T>(factory: () => T, deps: DependencyList) {\n const ref = useRef<MemoRef<T>>();\n\n let areEqual = true;\n for (let i = 0; i < deps.length; i++) {\n if (ref.current?.deps[i] !== deps[i]) {\n areEqual = false;\n break;\n }\n }\n\n if (ref.current === undefined || areEqual === false) {\n ref.current = { value: factory(), deps: deps };\n }\n\n return ref.current.value;\n}\n\n/**\n * Like React's useMemo, except it does a deep equality comparison with lodash's\n * isEqual on the dependency list.\n */\nexport function useDeepMemo<T>(factory: () => T, deps: DependencyList): T {\n const ref = useRef<MemoRef<T>>();\n if (ref.current === undefined || isEqual(deps, ref.current.deps) === false) {\n ref.current = { value: factory(), deps };\n }\n return ref.current.value;\n}\n"],"names":["useRef","isEqual","useMemoized","factory","deps","ref","areEqual","i","length","current","undefined","value","useDeepMemo"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,QAAwB,OAAO,CAAC;AAC/C,SAASC,OAAO,QAAQ,WAAW,CAAC;AAOpC;;;;CAIC,GACD,OAAO,SAASC,WAAW,CAAIC,OAAgB,EAAEC,IAAoB,EAAE;IACrE,MAAMC,GAAG,GAAGL,MAAM,EAAc,AAAC;IAEjC,IAAIM,QAAQ,GAAG,IAAI,AAAC;IACpB,IAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACI,MAAM,EAAED,CAAC,EAAE,CAAE;YAChCF,IAAW;QAAf,IAAIA,CAAAA,CAAAA,IAAW,GAAXA,GAAG,CAACI,OAAO,cAAXJ,IAAW,WAAM,GAAjBA,KAAAA,CAAiB,GAAjBA,IAAW,CAAED,IAAI,CAACG,CAAC,CAAC,MAAKH,IAAI,CAACG,CAAC,CAAC,EAAE;YACpCD,QAAQ,GAAG,KAAK,CAAC;YACjB,MAAM;QACR,CAAC;IACH,CAAC;IAED,IAAID,GAAG,CAACI,OAAO,KAAKC,SAAS,IAAIJ,QAAQ,KAAK,KAAK,EAAE;QACnDD,GAAG,CAACI,OAAO,GAAG;YAAEE,KAAK,EAAER,OAAO,EAAE;YAAEC,IAAI,EAAEA,IAAI;SAAE,CAAC;IACjD,CAAC;IAED,OAAOC,GAAG,CAACI,OAAO,CAACE,KAAK,CAAC;AAC3B,CAAC;AAED;;;CAGC,GACD,OAAO,SAASC,WAAW,CAAIT,OAAgB,EAAEC,IAAoB,EAAK;IACxE,MAAMC,GAAG,GAAGL,MAAM,EAAc,AAAC;IACjC,IAAIK,GAAG,CAACI,OAAO,KAAKC,SAAS,IAAIT,OAAO,CAACG,IAAI,EAAEC,GAAG,CAACI,OAAO,CAACL,IAAI,CAAC,KAAK,KAAK,EAAE;QAC1EC,GAAG,CAACI,OAAO,GAAG;YAAEE,KAAK,EAAER,OAAO,EAAE;YAAEC,IAAI;SAAE,CAAC;IAC3C,CAAC;IACD,OAAOC,GAAG,CAACI,OAAO,CAACE,KAAK,CAAC;AAC3B,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/memo.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useRef, DependencyList } from 'react';\nimport { isEqual } from 'lodash-es';\n\ntype MemoRef<T> = {\n value: T;\n deps: DependencyList;\n};\n\n/**\n * Like React's useMemo, but guarantees the value will only be recalulated if\n * a dependency changes. Uses strict equality (===) for comparison. (React's\n * useMemo does not offer this guarantee, it's only a performance optimization).\n */\nexport function useMemoized<T>(factory: () => T, deps: DependencyList) {\n const ref = useRef<MemoRef<T>>();\n\n let areEqual = true;\n for (let i = 0; i < deps.length; i++) {\n if (ref.current?.deps[i] !== deps[i]) {\n areEqual = false;\n break;\n }\n }\n\n if (ref.current === undefined || areEqual === false) {\n ref.current = { value: factory(), deps: deps };\n }\n\n return ref.current.value;\n}\n\n/**\n * Like React's useMemo, except it does a deep equality comparison with lodash's\n * isEqual on the dependency list.\n */\nexport function useDeepMemo<T>(factory: () => T, deps: DependencyList): T {\n const ref = useRef<MemoRef<T>>();\n if (ref.current === undefined || isEqual(deps, ref.current.deps) === false) {\n ref.current = { value: factory(), deps };\n }\n return ref.current.value;\n}\n"],"names":["useRef","isEqual","useMemoized","factory","deps","ref","areEqual","i","length","current","undefined","value","useDeepMemo"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,QAAwB,OAAO,CAAC;AAC/C,SAASC,OAAO,QAAQ,WAAW,CAAC;AAOpC;;;;CAIC,GACD,OAAO,SAASC,WAAW,CAAIC,OAAgB,EAAEC,IAAoB,EAAE;IACrE,MAAMC,GAAG,GAAGL,MAAM,EAAc,AAAC;IAEjC,IAAIM,QAAQ,GAAG,IAAI,AAAC;IACpB,IAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACI,MAAM,EAAED,CAAC,EAAE,CAAE;YAChCF,IAAW;QAAf,IAAIA,CAAAA,CAAAA,IAAW,GAAXA,GAAG,CAACI,OAAO,cAAXJ,IAAW,WAAM,GAAjBA,KAAAA,CAAiB,GAAjBA,IAAW,CAAED,IAAI,CAACG,CAAC,CAAC,MAAKH,IAAI,CAACG,CAAC,CAAC,EAAE;YACpCD,QAAQ,GAAG,KAAK,CAAC;YACjB,MAAM;QACR,CAAC;IACH,CAAC;IAED,IAAID,GAAG,CAACI,OAAO,KAAKC,SAAS,IAAIJ,QAAQ,KAAK,KAAK,EAAE;QACnDD,GAAG,CAACI,OAAO,GAAG;YAAEE,KAAK,EAAER,OAAO,EAAE;YAAEC,IAAI,EAAEA,IAAI;SAAE,CAAC;IACjD,CAAC;IAED,OAAOC,GAAG,CAACI,OAAO,CAACE,KAAK,CAAC;AAC3B,CAAC;AAED;;;CAGC,GACD,OAAO,SAASC,WAAW,CAAIT,OAAgB,EAAEC,IAAoB,EAAK;IACxE,MAAMC,GAAG,GAAGL,MAAM,EAAc,AAAC;IACjC,IAAIK,GAAG,CAACI,OAAO,KAAKC,SAAS,IAAIT,OAAO,CAACG,IAAI,EAAEC,GAAG,CAACI,OAAO,CAACL,IAAI,CAAC,KAAK,KAAK,EAAE;QAC1EC,GAAG,CAACI,OAAO,GAAG;YAAEE,KAAK,EAAER,OAAO,EAAE;YAAEC,IAAI;SAAE,CAAC;IAC3C,CAAC;IACD,OAAOC,GAAG,CAACI,OAAO,CAACE,KAAK,CAAC;AAC3B,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/panel-refs.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DashboardSpec, PanelRef } from '../model';\n\n/**\n * Resolve a PanelRef (JSON reference) against the provided DashboardSpec to\n * a PanelDefinition.\n */\nexport function resolvePanelRef(spec: DashboardSpec, panelRef: PanelRef) {\n const panelsKey = getPanelKeyFromRef(panelRef);\n const panelDefinition = spec.panels[panelsKey];\n if (panelDefinition === undefined) {\n throw new Error(`Could not resolve panels reference ${panelRef.$ref}`);\n }\n return panelDefinition;\n}\n\n// Currently, panel refs are prefixed with `#/spec/panels/`. If that format changes, we'll definitely need to update\n// the code in here relying on it being that format.\nconst REF_PREFIX_LENGTH = 14;\n\n/**\n * Gets the unique key for a panel from a PanelRef.\n */\nexport function getPanelKeyFromRef(panelRef: PanelRef) {\n return panelRef.$ref.substring(REF_PREFIX_LENGTH);\n}\n\n/**\n * Creates a PanelRef for a panel with the given key.\n */\nexport function createPanelRef(panelKey: string): PanelRef {\n return { $ref: `#/spec/panels/${panelKey}` };\n}\n"],"names":["resolvePanelRef","spec","panelRef","panelsKey","getPanelKeyFromRef","panelDefinition","panels","undefined","Error","$ref","REF_PREFIX_LENGTH","substring","createPanelRef","panelKey"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC;;;CAGC,GACD,OAAO,SAASA,eAAe,CAACC,IAAmB,EAAEC,QAAkB,EAAE;IACvE,MAAMC,SAAS,GAAGC,kBAAkB,CAACF,QAAQ,CAAC,AAAC;IAC/C,MAAMG,eAAe,GAAGJ,IAAI,CAACK,MAAM,CAACH,SAAS,CAAC,AAAC;IAC/C,IAAIE,eAAe,KAAKE,SAAS,EAAE;QACjC,MAAM,IAAIC,KAAK,CAAC,CAAC,mCAAmC,EAAEN,QAAQ,CAACO,IAAI,CAAC,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,OAAOJ,eAAe,CAAC;AACzB,CAAC;AAED,oHAAoH;AACpH,oDAAoD;AACpD,MAAMK,iBAAiB,GAAG,EAAE,AAAC;AAE7B;;CAEC,GACD,OAAO,SAASN,kBAAkB,CAACF,QAAkB,EAAE;IACrD,OAAOA,QAAQ,CAACO,IAAI,CAACE,SAAS,CAACD,iBAAiB,CAAC,CAAC;AACpD,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,cAAc,CAACC,QAAgB,EAAY;IACzD,OAAO;QAAEJ,IAAI,EAAE,CAAC,cAAc,EAAEI,QAAQ,CAAC,CAAC;KAAE,CAAC;AAC/C,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/panel-refs.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DashboardSpec, PanelRef } from '../model';\n\n/**\n * Resolve a PanelRef (JSON reference) against the provided DashboardSpec to\n * a PanelDefinition.\n */\nexport function resolvePanelRef(spec: DashboardSpec, panelRef: PanelRef) {\n const panelsKey = getPanelKeyFromRef(panelRef);\n const panelDefinition = spec.panels[panelsKey];\n if (panelDefinition === undefined) {\n throw new Error(`Could not resolve panels reference ${panelRef.$ref}`);\n }\n return panelDefinition;\n}\n\n// Currently, panel refs are prefixed with `#/spec/panels/`. If that format changes, we'll definitely need to update\n// the code in here relying on it being that format.\nconst REF_PREFIX_LENGTH = 14;\n\n/**\n * Gets the unique key for a panel from a PanelRef.\n */\nexport function getPanelKeyFromRef(panelRef: PanelRef) {\n return panelRef.$ref.substring(REF_PREFIX_LENGTH);\n}\n\n/**\n * Creates a PanelRef for a panel with the given key.\n */\nexport function createPanelRef(panelKey: string): PanelRef {\n return { $ref: `#/spec/panels/${panelKey}` };\n}\n"],"names":["resolvePanelRef","spec","panelRef","panelsKey","getPanelKeyFromRef","panelDefinition","panels","undefined","Error","$ref","REF_PREFIX_LENGTH","substring","createPanelRef","panelKey"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC;;;CAGC,GACD,OAAO,SAASA,eAAe,CAACC,IAAmB,EAAEC,QAAkB,EAAE;IACvE,MAAMC,SAAS,GAAGC,kBAAkB,CAACF,QAAQ,CAAC,AAAC;IAC/C,MAAMG,eAAe,GAAGJ,IAAI,CAACK,MAAM,CAACH,SAAS,CAAC,AAAC;IAC/C,IAAIE,eAAe,KAAKE,SAAS,EAAE;QACjC,MAAM,IAAIC,KAAK,CAAC,CAAC,mCAAmC,EAAEN,QAAQ,CAACO,IAAI,CAAC,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,OAAOJ,eAAe,CAAC;AACzB,CAAC;AAED,oHAAoH;AACpH,oDAAoD;AACpD,MAAMK,iBAAiB,GAAG,EAAE,AAAC;AAE7B;;CAEC,GACD,OAAO,SAASN,kBAAkB,CAACF,QAAkB,EAAE;IACrD,OAAOA,QAAQ,CAACO,IAAI,CAACE,SAAS,CAACD,iBAAiB,CAAC,CAAC;AACpD,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,cAAc,CAACC,QAAgB,EAAY;IACzD,OAAO;QAAEJ,IAAI,EAAE,CAAC,cAAc,EAAEI,QAAQ,CAAC,CAAC;KAAE,CAAC;AAC/C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/core",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "Core functionality consumed by both the Perses UI and plugins",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",