@perses-dev/components 0.54.0-beta.2 → 0.54.0-beta.4

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 (50) hide show
  1. package/dist/cjs/utils/index.js +7 -0
  2. package/dist/cjs/utils/mathjs.js +14 -3
  3. package/dist/cjs/utils/regexp.js +54 -0
  4. package/dist/cjs/utils/request-interpolation.js +33 -1
  5. package/dist/cjs/utils/text.js +52 -0
  6. package/dist/cjs/utils/time-series-data.js +141 -0
  7. package/dist/cjs/utils/trace-data.js +25 -0
  8. package/dist/cjs/utils/transform-data.js +157 -0
  9. package/dist/cjs/utils/types.js +16 -0
  10. package/dist/cjs/utils/value-mapping.js +105 -0
  11. package/dist/utils/index.d.ts +7 -0
  12. package/dist/utils/index.d.ts.map +1 -1
  13. package/dist/utils/index.js +7 -0
  14. package/dist/utils/index.js.map +1 -1
  15. package/dist/utils/mathjs.d.ts +8 -1
  16. package/dist/utils/mathjs.d.ts.map +1 -1
  17. package/dist/utils/mathjs.js +5 -2
  18. package/dist/utils/mathjs.js.map +1 -1
  19. package/dist/utils/regexp.d.ts +11 -0
  20. package/dist/utils/regexp.d.ts.map +1 -0
  21. package/dist/utils/regexp.js +42 -0
  22. package/dist/utils/regexp.js.map +1 -0
  23. package/dist/utils/request-interpolation.d.ts.map +1 -1
  24. package/dist/utils/request-interpolation.js +34 -2
  25. package/dist/utils/request-interpolation.js.map +1 -1
  26. package/dist/utils/text.d.ts +8 -0
  27. package/dist/utils/text.d.ts.map +1 -0
  28. package/dist/utils/text.js +39 -0
  29. package/dist/utils/text.js.map +1 -0
  30. package/dist/utils/time-series-data.d.ts +15 -0
  31. package/dist/utils/time-series-data.d.ts.map +1 -0
  32. package/dist/utils/time-series-data.js +130 -0
  33. package/dist/utils/time-series-data.js.map +1 -0
  34. package/dist/utils/trace-data.d.ts +37 -0
  35. package/dist/utils/trace-data.d.ts.map +1 -0
  36. package/dist/utils/trace-data.js +17 -0
  37. package/dist/utils/trace-data.js.map +1 -0
  38. package/dist/utils/transform-data.d.ts +7 -0
  39. package/dist/utils/transform-data.d.ts.map +1 -0
  40. package/dist/utils/transform-data.js +214 -0
  41. package/dist/utils/transform-data.js.map +1 -0
  42. package/dist/utils/types.d.ts +2 -0
  43. package/dist/utils/types.d.ts.map +1 -0
  44. package/dist/utils/types.js +15 -0
  45. package/dist/utils/types.js.map +1 -0
  46. package/dist/utils/value-mapping.d.ts +3 -0
  47. package/dist/utils/value-mapping.d.ts.map +1 -0
  48. package/dist/utils/value-mapping.js +97 -0
  49. package/dist/utils/value-mapping.js.map +1 -0
  50. package/package.json +2 -2
@@ -0,0 +1,214 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ /*
14
+ * Join: Regroup rows with equal cell value in a column.
15
+ * If there are multiple line with same value, next row values override the current one
16
+ *
17
+ * Example: Join on 'mount' column
18
+ * INPUT:
19
+ * | timestamp | value #1 | value #3 | mount |
20
+ * |------------|----------|----------|-----------|
21
+ * | 1630000000 | 1 | | / |
22
+ * | 1630000000 | 2 | | /boot/efi |
23
+ * | 1630000000 | | 3 | / |
24
+ * | 1630000000 | | 4 | /boot/efi |
25
+ *
26
+ * OUTPUT:
27
+ * | timestamp | value #1 | value #3 | mount |
28
+ * |------------|----------|----------|-----------|
29
+ * | 1630000000 | 1 | 3 | / |
30
+ * | 1630000000 | 2 | 4 | /boot/efi |
31
+ */ export function applyJoinTransform(data, columns) {
32
+ // If column is undefined or empty, return data as is
33
+ if (columns.length === 0) {
34
+ return data;
35
+ }
36
+ const rowHashed = {};
37
+ for (const row of data){
38
+ const rowHash = Object.keys(row).filter((k)=>columns.includes(k)).map((k)=>row[k]).join('|');
39
+ const rowHashedValue = rowHashed[rowHash];
40
+ if (rowHashedValue) {
41
+ rowHashed[rowHash] = {
42
+ ...rowHashedValue,
43
+ ...row
44
+ };
45
+ } else {
46
+ rowHashed[rowHash] = {
47
+ ...row
48
+ };
49
+ }
50
+ }
51
+ return Object.values(rowHashed);
52
+ }
53
+ /*
54
+ * Merges selected columns into a single column.
55
+ *
56
+ * Example: Merge columns 'value #1' and 'value #2' into a single column 'MERGED'
57
+ * INPUT:
58
+ * +------------+----------+----------+-----------+-----------+
59
+ * | timestamp | value #1 | value #2 | mount #1 | mount #2 |
60
+ * +------------+----------+----------+-----------+-----------+
61
+ * | 1630000000 | 1 | | / | |
62
+ * | 1630000000 | 2 | | /boot/efi | |
63
+ * | 1630000000 | | 3 | | / |
64
+ * | 1630000000 | | 4 | | /boot/efi |
65
+ * +------------+----------+----------+-----------+-----------+
66
+ *
67
+ * OUTPUT:
68
+ * +------------+--------+-----------+-----------+
69
+ * | timestamp | MERGED | mount #1 | mount #2 |
70
+ * +------------+--------+-----------+-----------+
71
+ * | 1630000000 | 1 | / | |
72
+ * | 1630000000 | 2 | /boot/efi | |
73
+ * | 1630000000 | 2 | | / |
74
+ * | 1630000000 | 3 | | /boot/efi |
75
+ * +------------+--------+-----------+-----------+
76
+ */ export function applyMergeColumnsTransform(data, selectedColumns, outputName) {
77
+ const result = [];
78
+ for (const row of data){
79
+ const columns = Object.keys(row).filter((k)=>selectedColumns.includes(k));
80
+ const selectedColumnValues = {};
81
+ for (const column of columns){
82
+ selectedColumnValues[column] = row[column];
83
+ delete row[column];
84
+ }
85
+ for (const column of columns){
86
+ result.push({
87
+ ...row,
88
+ [outputName]: selectedColumnValues[column]
89
+ });
90
+ }
91
+ if (columns.length === 0) {
92
+ result.push(row);
93
+ }
94
+ }
95
+ return result;
96
+ }
97
+ /*
98
+ * Merge Indexed Columns: All indexed columns are merged to one column
99
+ *
100
+ * Example: Join on 'value' column
101
+ * INPUT:
102
+ * | timestamp #1 | timestamp #2 | value #1 | value #2 | instance #1 | instance #2 |
103
+ * |--------------|--------------|----------|----------|-------------|-------------|
104
+ * | 1630000000 | | 55 | | toto | |
105
+ * | 1630000000 | | 33 | | toto | |
106
+ * | 1630000000 | | 45 | | toto | |
107
+ * | | 1630000000 | | 112 | | titi |
108
+ * | | 1630000000 | | 20 | | titi |
109
+ * | | 1630000000 | | 10 | | titi |
110
+ *
111
+ * OUTPUT:
112
+ * | timestamp #1 | timestamp #2 | value | instance #1 | instance #2 |
113
+ * |--------------|--------------|-------|-------------|-------------|
114
+ * | 1630000000 | | 55 | toto | |
115
+ * | 1630000000 | | 33 | toto | |
116
+ * | 1630000000 | | 45 | toto | |
117
+ * | | 1630000000 | 112 | | titi |
118
+ * | | 1630000000 | 20 | | titi |
119
+ * | | 1630000000 | 10 | | titi |
120
+ */ export function applyMergeIndexedColumnsTransform(data, column) {
121
+ const result = [];
122
+ for (const entry of data){
123
+ const indexedColumns = Object.keys(entry).filter((k)=>new RegExp('^((' + column + ' #\\d+)|(' + column + '))$').test(k));
124
+ const indexedColumnValues = {};
125
+ for (const indexedColumn of indexedColumns){
126
+ indexedColumnValues[indexedColumn] = entry[indexedColumn];
127
+ delete entry[indexedColumn];
128
+ }
129
+ for (const indexedColumn of indexedColumns){
130
+ result.push({
131
+ ...entry,
132
+ [column]: indexedColumnValues[indexedColumn]
133
+ });
134
+ }
135
+ if (indexedColumns.length === 0) {
136
+ result.push(entry);
137
+ }
138
+ }
139
+ return result;
140
+ }
141
+ /*
142
+ * Merge Indexed Columns: All indexed columns are merged to one column
143
+ *
144
+ * INPUT:
145
+ * | timestamp | value #1 | value #2 | mount #1 | mount #2 | instance #1 | instance #2 | env #1 | env #2 |
146
+ * |------------|----------|----------|-----------|-----------|-------------|-------------|--------|--------|
147
+ * | 1630000000 | 1 | | / | | test:44 | | prd | |
148
+ * | 1630000000 | 2 | | /boot/efi | | test:44 | | prd | |
149
+ * | 1630000000 | | 5 | | / | | test:44 | | prd |
150
+ * | 1630000000 | | 6 | | /boot/efi | | test:44 | | prd |
151
+ *
152
+ * OUTPUT:
153
+ * | timestamp | value #1 | value #2 | mount | instance | env |
154
+ * |------------|----------|----------|-----------|----------|-----|
155
+ * | 1630000000 | 1 | 5 | / | test:44 | prd |
156
+ * | 1630000000 | 2 | 6 | /boot/efi | test:44 | prd |
157
+ */ export function applyMergeSeriesTransform(data) {
158
+ let result = [
159
+ ...data
160
+ ];
161
+ const labelColumns = Array.from(new Set(data.flatMap(Object.keys).map((label)=>label.replace(/ #\d+/, '')).filter((label)=>label !== 'value')));
162
+ for (const label of labelColumns){
163
+ result = applyMergeIndexedColumnsTransform(result, label);
164
+ }
165
+ result = applyJoinTransform(result, labelColumns);
166
+ return result;
167
+ }
168
+ /*
169
+ * Transforms query data with the given transforms
170
+ */ export function transformData(data, transforms) {
171
+ let result = data;
172
+ // Apply transforms by their orders
173
+ for (const transform of transforms ?? []){
174
+ if (transform.spec.disabled) continue;
175
+ switch(transform.kind){
176
+ case 'JoinByColumnValue':
177
+ {
178
+ if (transform.spec.columns && transform.spec.columns.length > 0) {
179
+ result = applyJoinTransform(result, transform.spec.columns);
180
+ }
181
+ break;
182
+ }
183
+ case 'MergeIndexedColumns':
184
+ {
185
+ if (transform.spec.column) {
186
+ result = applyMergeIndexedColumnsTransform(result, transform.spec.column);
187
+ }
188
+ break;
189
+ }
190
+ case 'MergeColumns':
191
+ {
192
+ if (transform.spec.columns && transform.spec.columns.length > 0 && transform.spec.name) {
193
+ result = applyMergeColumnsTransform(result, transform.spec.columns, transform.spec.name);
194
+ }
195
+ break;
196
+ }
197
+ case 'MergeSeries':
198
+ {
199
+ result = applyMergeSeriesTransform(result);
200
+ break;
201
+ }
202
+ }
203
+ }
204
+ // Ordering data column alphabetically
205
+ result = result.map((row)=>{
206
+ return Object.keys(row).sort().reduce((obj, key)=>{
207
+ obj[key] = row[key];
208
+ return obj;
209
+ }, {});
210
+ });
211
+ return result;
212
+ }
213
+
214
+ //# sourceMappingURL=transform-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/transform-data.ts"],"sourcesContent":["// Copyright 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 { Transform } from '../model';\n\n/*\n * Join: Regroup rows with equal cell value in a column.\n * If there are multiple line with same value, next row values override the current one\n *\n * Example: Join on 'mount' column\n * INPUT:\n * | timestamp | value #1 | value #3 | mount |\n * |------------|----------|----------|-----------|\n * | 1630000000 | 1 | | / |\n * | 1630000000 | 2 | | /boot/efi |\n * | 1630000000 | | 3 | / |\n * | 1630000000 | | 4 | /boot/efi |\n *\n * OUTPUT:\n * | timestamp | value #1 | value #3 | mount |\n * |------------|----------|----------|-----------|\n * | 1630000000 | 1 | 3 | / |\n * | 1630000000 | 2 | 4 | /boot/efi |\n */\nexport function applyJoinTransform(\n data: Array<Record<string, unknown>>,\n columns: string[]\n): Array<Record<string, unknown>> {\n // If column is undefined or empty, return data as is\n if (columns.length === 0) {\n return data;\n }\n\n const rowHashed: { [key: string]: Record<string, unknown> } = {};\n\n for (const row of data) {\n const rowHash = Object.keys(row)\n .filter((k) => columns.includes(k))\n .map((k) => row[k])\n .join('|');\n\n const rowHashedValue = rowHashed[rowHash];\n if (rowHashedValue) {\n rowHashed[rowHash] = { ...rowHashedValue, ...row };\n } else {\n rowHashed[rowHash] = { ...row };\n }\n }\n return Object.values(rowHashed);\n}\n\n/*\n * Merges selected columns into a single column.\n *\n * Example: Merge columns 'value #1' and 'value #2' into a single column 'MERGED'\n * INPUT:\n * +------------+----------+----------+-----------+-----------+\n * | timestamp | value #1 | value #2 | mount #1 | mount #2 |\n * +------------+----------+----------+-----------+-----------+\n * | 1630000000 | 1 | | / | |\n * | 1630000000 | 2 | | /boot/efi | |\n * | 1630000000 | | 3 | | / |\n * | 1630000000 | | 4 | | /boot/efi |\n * +------------+----------+----------+-----------+-----------+\n *\n * OUTPUT:\n * +------------+--------+-----------+-----------+\n * | timestamp | MERGED | mount #1 | mount #2 |\n * +------------+--------+-----------+-----------+\n * | 1630000000 | 1 | / | |\n * | 1630000000 | 2 | /boot/efi | |\n * | 1630000000 | 2 | | / |\n * | 1630000000 | 3 | | /boot/efi |\n * +------------+--------+-----------+-----------+\n */\nexport function applyMergeColumnsTransform(\n data: Array<Record<string, unknown>>,\n selectedColumns: string[],\n outputName: string\n): Array<Record<string, unknown>> {\n const result: Array<Record<string, unknown>> = [];\n\n for (const row of data) {\n const columns = Object.keys(row).filter((k) => selectedColumns.includes(k));\n\n const selectedColumnValues: Record<string, unknown> = {};\n\n for (const column of columns) {\n selectedColumnValues[column] = row[column];\n delete row[column];\n }\n\n for (const column of columns) {\n result.push({ ...row, [outputName]: selectedColumnValues[column] });\n }\n\n if (columns.length === 0) {\n result.push(row);\n }\n }\n\n return result;\n}\n\n/*\n * Merge Indexed Columns: All indexed columns are merged to one column\n *\n * Example: Join on 'value' column\n * INPUT:\n * | timestamp #1 | timestamp #2 | value #1 | value #2 | instance #1 | instance #2 |\n * |--------------|--------------|----------|----------|-------------|-------------|\n * | 1630000000 | | 55 | | toto | |\n * | 1630000000 | | 33 | | toto | |\n * | 1630000000 | | 45 | | toto | |\n * | | 1630000000 | | 112 | | titi |\n * | | 1630000000 | | 20 | | titi |\n * | | 1630000000 | | 10 | | titi |\n *\n * OUTPUT:\n * | timestamp #1 | timestamp #2 | value | instance #1 | instance #2 |\n * |--------------|--------------|-------|-------------|-------------|\n * | 1630000000 | | 55 | toto | |\n * | 1630000000 | | 33 | toto | |\n * | 1630000000 | | 45 | toto | |\n * | | 1630000000 | 112 | | titi |\n * | | 1630000000 | 20 | | titi |\n * | | 1630000000 | 10 | | titi |\n */\nexport function applyMergeIndexedColumnsTransform(\n data: Array<Record<string, unknown>>,\n column: string\n): Array<Record<string, unknown>> {\n const result: Array<Record<string, unknown>> = [];\n\n for (const entry of data) {\n const indexedColumns = Object.keys(entry).filter((k) =>\n new RegExp('^((' + column + ' #\\\\d+)|(' + column + '))$').test(k)\n );\n const indexedColumnValues: Record<string, unknown> = {};\n\n for (const indexedColumn of indexedColumns) {\n indexedColumnValues[indexedColumn] = entry[indexedColumn];\n delete entry[indexedColumn];\n }\n\n for (const indexedColumn of indexedColumns) {\n result.push({ ...entry, [column]: indexedColumnValues[indexedColumn] });\n }\n\n if (indexedColumns.length === 0) {\n result.push(entry);\n }\n }\n\n return result;\n}\n\n/*\n * Merge Indexed Columns: All indexed columns are merged to one column\n *\n * INPUT:\n * | timestamp | value #1 | value #2 | mount #1 | mount #2 | instance #1 | instance #2 | env #1 | env #2 |\n * |------------|----------|----------|-----------|-----------|-------------|-------------|--------|--------|\n * | 1630000000 | 1 | | / | | test:44 | | prd | |\n * | 1630000000 | 2 | | /boot/efi | | test:44 | | prd | |\n * | 1630000000 | | 5 | | / | | test:44 | | prd |\n * | 1630000000 | | 6 | | /boot/efi | | test:44 | | prd |\n *\n * OUTPUT:\n * | timestamp | value #1 | value #2 | mount | instance | env |\n * |------------|----------|----------|-----------|----------|-----|\n * | 1630000000 | 1 | 5 | / | test:44 | prd |\n * | 1630000000 | 2 | 6 | /boot/efi | test:44 | prd |\n */\nexport function applyMergeSeriesTransform(data: Array<Record<string, unknown>>): Array<Record<string, unknown>> {\n let result: Array<Record<string, unknown>> = [...data];\n\n const labelColumns = Array.from(\n new Set(\n data\n .flatMap(Object.keys)\n .map((label) => label.replace(/ #\\d+/, ''))\n .filter((label) => label !== 'value')\n )\n );\n\n for (const label of labelColumns) {\n result = applyMergeIndexedColumnsTransform(result, label);\n }\n\n result = applyJoinTransform(result, labelColumns);\n\n return result;\n}\n\n/*\n * Transforms query data with the given transforms\n */\nexport function transformData(\n data: Array<Record<string, unknown>>,\n transforms: Transform[]\n): Array<Record<string, unknown>> {\n let result: Array<Record<string, unknown>> = data;\n\n // Apply transforms by their orders\n for (const transform of transforms ?? []) {\n if (transform.spec.disabled) continue;\n\n switch (transform.kind) {\n case 'JoinByColumnValue': {\n if (transform.spec.columns && transform.spec.columns.length > 0) {\n result = applyJoinTransform(result, transform.spec.columns);\n }\n break;\n }\n case 'MergeIndexedColumns': {\n if (transform.spec.column) {\n result = applyMergeIndexedColumnsTransform(result, transform.spec.column);\n }\n break;\n }\n case 'MergeColumns': {\n if (transform.spec.columns && transform.spec.columns.length > 0 && transform.spec.name) {\n result = applyMergeColumnsTransform(result, transform.spec.columns, transform.spec.name);\n }\n break;\n }\n case 'MergeSeries': {\n result = applyMergeSeriesTransform(result);\n break;\n }\n }\n }\n\n // Ordering data column alphabetically\n result = result.map((row) => {\n return Object.keys(row)\n .sort()\n .reduce((obj: Record<string, unknown>, key: string) => {\n obj[key] = row[key];\n return obj;\n }, {});\n });\n return result;\n}\n"],"names":["applyJoinTransform","data","columns","length","rowHashed","row","rowHash","Object","keys","filter","k","includes","map","join","rowHashedValue","values","applyMergeColumnsTransform","selectedColumns","outputName","result","selectedColumnValues","column","push","applyMergeIndexedColumnsTransform","entry","indexedColumns","RegExp","test","indexedColumnValues","indexedColumn","applyMergeSeriesTransform","labelColumns","Array","from","Set","flatMap","label","replace","transformData","transforms","transform","spec","disabled","kind","name","sort","reduce","obj","key"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASA,mBACdC,IAAoC,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AaD,cAAc,EAAE,CAAE;QACxC,IAAIC,UAAUC,IAAI,CAACC,QAAQ,EAAE;QAE7B,OAAQF,UAAUG,IAAI;YACpB,KAAK;gBAAqB;oBACxB,IAAIH,UAAUC,IAAI,CAACvC,OAAO,IAAIsC,UAAUC,IAAI,CAACvC,OAAO,CAACC,MAAM,GAAG,GAAG;wBAC/DgB,SAASnB,mBAAmBmB,QAAQqB,UAAUC,IAAI,CAACvC,OAAO;oBAC5D;oBACA;gBACF;YACA,KAAK;gBAAuB;oBAC1B,IAAIsC,UAAUC,IAAI,CAACpB,MAAM,EAAE;wBACzBF,SAASI,kCAAkCJ,QAAQqB,UAAUC,IAAI,CAACpB,MAAM;oBAC1E;oBACA;gBACF;YACA,KAAK;gBAAgB;oBACnB,IAAImB,UAAUC,IAAI,CAACvC,OAAO,IAAIsC,UAAUC,IAAI,CAACvC,OAAO,CAACC,MAAM,GAAG,KAAKqC,UAAUC,IAAI,CAACG,IAAI,EAAE;wBACtFzB,SAASH,2BAA2BG,QAAQqB,UAAUC,IAAI,CAACvC,OAAO,EAAEsC,UAAUC,IAAI,CAACG,IAAI;oBACzF;oBACA;gBACF;YACA,KAAK;gBAAe;oBAClBzB,SAASW,0BAA0BX;oBACnC;gBACF;QACF;IACF;IAEA,sCAAsC;IACtCA,SAASA,OAAOP,GAAG,CAAC,CAACP;QACnB,OAAOE,OAAOC,IAAI,CAACH,KAChBwC,IAAI,GACJC,MAAM,CAAC,CAACC,KAA8BC;YACrCD,GAAG,CAACC,IAAI,GAAG3C,GAAG,CAAC2C,IAAI;YACnB,OAAOD;QACT,GAAG,CAAC;IACR;IACA,OAAO5B;AACT"}
@@ -0,0 +1,2 @@
1
+ export type DispatchWithPromise<A> = (value: A) => Promise<void>;
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export { };
14
+
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/types.ts"],"sourcesContent":["// Copyright 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 type DispatchWithPromise<A> = (value: A) => Promise<void>;\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAAiE"}
@@ -0,0 +1,3 @@
1
+ import { MappedValue, ValueMapping } from '../model';
2
+ export declare function applyValueMapping(value: number | string, mappings?: ValueMapping[]): MappedValue;
3
+ //# sourceMappingURL=value-mapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-mapping.d.ts","sourceRoot":"","sources":["../../src/utils/value-mapping.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGrD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,GAAE,YAAY,EAAO,GAAG,WAAW,CAkEpG"}
@@ -0,0 +1,97 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { createRegexFromString } from './regexp';
14
+ export function applyValueMapping(value, mappings = []) {
15
+ if (!mappings.length) {
16
+ return {
17
+ value
18
+ };
19
+ }
20
+ const mappedItem = {
21
+ value
22
+ };
23
+ mappings.forEach((mapping)=>{
24
+ switch(mapping.kind){
25
+ case 'Value':
26
+ {
27
+ const valueOptions = mapping.spec;
28
+ if (String(valueOptions.value) === String(value)) {
29
+ mappedItem.value = valueOptions.result.value || mappedItem.value;
30
+ mappedItem.color = valueOptions.result.color;
31
+ }
32
+ break;
33
+ }
34
+ case 'Range':
35
+ {
36
+ const rangeOptions = mapping.spec;
37
+ const newValue = value;
38
+ if (rangeOptions.from === undefined && rangeOptions.to === undefined) {
39
+ break;
40
+ }
41
+ const from = rangeOptions.from !== undefined ? rangeOptions.from : -Infinity;
42
+ const to = rangeOptions.to !== undefined ? rangeOptions.to : Infinity;
43
+ if (newValue >= from && newValue <= to) {
44
+ mappedItem.value = rangeOptions.result.value || mappedItem.value;
45
+ mappedItem.color = rangeOptions.result.color;
46
+ }
47
+ break;
48
+ }
49
+ case 'Regex':
50
+ {
51
+ const regexOptions = mapping.spec;
52
+ const stringValue = value.toString();
53
+ if (!regexOptions.pattern) {
54
+ break;
55
+ }
56
+ const regex = createRegexFromString(regexOptions.pattern);
57
+ if (stringValue.match(regex)) {
58
+ if (regexOptions.result.value !== null) {
59
+ mappedItem.value = stringValue.replace(regex, regexOptions.result.value.toString() || '') || mappedItem.value;
60
+ mappedItem.color = regexOptions.result.color;
61
+ }
62
+ }
63
+ break;
64
+ }
65
+ case 'Misc':
66
+ {
67
+ const miscOptions = mapping.spec;
68
+ if (isMiscValueMatch(miscOptions.value, value)) {
69
+ mappedItem.value = miscOptions.result.value || mappedItem.value;
70
+ mappedItem.color = miscOptions.result.color;
71
+ }
72
+ break;
73
+ }
74
+ default:
75
+ break;
76
+ }
77
+ });
78
+ return mappedItem;
79
+ }
80
+ function isMiscValueMatch(miscValue, value) {
81
+ switch(miscValue){
82
+ case 'empty':
83
+ return value === '';
84
+ case 'null':
85
+ return value === null || value === undefined;
86
+ case 'NaN':
87
+ return Number.isNaN(value);
88
+ case 'true':
89
+ return value === true;
90
+ case 'false':
91
+ return value === false;
92
+ default:
93
+ return false;
94
+ }
95
+ }
96
+
97
+ //# sourceMappingURL=value-mapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/value-mapping.ts"],"sourcesContent":["// Copyright 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 { MappedValue, ValueMapping } from '../model';\nimport { createRegexFromString } from './regexp';\n\nexport function applyValueMapping(value: number | string, mappings: ValueMapping[] = []): MappedValue {\n if (!mappings.length) {\n return { value };\n }\n\n const mappedItem: MappedValue = { value };\n\n mappings.forEach((mapping) => {\n switch (mapping.kind) {\n case 'Value': {\n const valueOptions = mapping.spec;\n\n if (String(valueOptions.value) === String(value)) {\n mappedItem.value = valueOptions.result.value || mappedItem.value;\n mappedItem.color = valueOptions.result.color;\n }\n break;\n }\n case 'Range': {\n const rangeOptions = mapping.spec;\n const newValue = value as number;\n\n if (rangeOptions.from === undefined && rangeOptions.to === undefined) {\n break;\n }\n\n const from = rangeOptions.from !== undefined ? rangeOptions.from : -Infinity;\n const to = rangeOptions.to !== undefined ? rangeOptions.to : Infinity;\n if (newValue >= from && newValue <= to) {\n mappedItem.value = rangeOptions.result.value || mappedItem.value;\n mappedItem.color = rangeOptions.result.color;\n }\n break;\n }\n case 'Regex': {\n const regexOptions = mapping.spec;\n const stringValue = value.toString();\n\n if (!regexOptions.pattern) {\n break;\n }\n\n const regex = createRegexFromString(regexOptions.pattern);\n\n if (stringValue.match(regex)) {\n if (regexOptions.result.value !== null) {\n mappedItem.value =\n stringValue.replace(regex, regexOptions.result.value.toString() || '') || mappedItem.value;\n mappedItem.color = regexOptions.result.color;\n }\n }\n break;\n }\n case 'Misc': {\n const miscOptions = mapping.spec;\n if (isMiscValueMatch(miscOptions.value, value)) {\n mappedItem.value = miscOptions.result.value || mappedItem.value;\n mappedItem.color = miscOptions.result.color;\n }\n break;\n }\n default:\n break;\n }\n });\n return mappedItem;\n}\n\nfunction isMiscValueMatch(miscValue: string, value: number | string | boolean): boolean {\n switch (miscValue) {\n case 'empty':\n return value === '';\n case 'null':\n return value === null || value === undefined;\n case 'NaN':\n return Number.isNaN(value);\n case 'true':\n return value === true;\n case 'false':\n return value === false;\n default:\n return false;\n }\n}\n"],"names":["createRegexFromString","applyValueMapping","value","mappings","length","mappedItem","forEach","mapping","kind","valueOptions","spec","String","result","color","rangeOptions","newValue","from","undefined","to","Infinity","regexOptions","stringValue","toString","pattern","regex","match","replace","miscOptions","isMiscValueMatch","miscValue","Number","isNaN"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC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AAaG,OAAO,EAAE;wBACzB;oBACF;oBAEA,MAAMC,QAAQxB,sBAAsBoB,aAAaG,OAAO;oBAExD,IAAIF,YAAYI,KAAK,CAACD,QAAQ;wBAC5B,IAAIJ,aAAaR,MAAM,CAACV,KAAK,KAAK,MAAM;4BACtCG,WAAWH,KAAK,GACdmB,YAAYK,OAAO,CAACF,OAAOJ,aAAaR,MAAM,CAACV,KAAK,CAACoB,QAAQ,MAAM,OAAOjB,WAAWH,KAAK;4BAC5FG,WAAWQ,KAAK,GAAGO,aAAaR,MAAM,CAACC,KAAK;wBAC9C;oBACF;oBACA;gBACF;YACA,KAAK;gBAAQ;oBACX,MAAMc,cAAcpB,QAAQG,IAAI;oBAChC,IAAIkB,iBAAiBD,YAAYzB,KAAK,EAAEA,QAAQ;wBAC9CG,WAAWH,KAAK,GAAGyB,YAAYf,MAAM,CAACV,KAAK,IAAIG,WAAWH,KAAK;wBAC/DG,WAAWQ,KAAK,GAAGc,YAAYf,MAAM,CAACC,KAAK;oBAC7C;oBACA;gBACF;YACA;gBACE;QACJ;IACF;IACA,OAAOR;AACT;AAEA,SAASuB,iBAAiBC,SAAiB,EAAE3B,KAAgC;IAC3E,OAAQ2B;QACN,KAAK;YACH,OAAO3B,UAAU;QACnB,KAAK;YACH,OAAOA,UAAU,QAAQA,UAAUe;QACrC,KAAK;YACH,OAAOa,OAAOC,KAAK,CAAC7B;QACtB,KAAK;YACH,OAAOA,UAAU;QACnB,KAAK;YACH,OAAOA,UAAU;QACnB;YACE,OAAO;IACX;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/components",
3
- "version": "0.54.0-beta.2",
3
+ "version": "0.54.0-beta.4",
4
4
  "description": "Common UI components used across Perses features",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -35,7 +35,7 @@
35
35
  "@fontsource/inter": "^5.0.0",
36
36
  "@mui/x-date-pickers": "^7.23.1",
37
37
  "@perses-dev/spec": "0.2.0-beta.0",
38
- "@perses-dev/client": "0.54.0-beta.2",
38
+ "@perses-dev/client": "0.54.0-beta.4",
39
39
  "numbro": "^2.3.6",
40
40
  "@tanstack/match-sorter-utils": "^8.19.4",
41
41
  "@tanstack/react-table": "^8.20.5",