@perses-dev/plugin-system 0.46.0 → 0.47.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 (188) hide show
  1. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +70 -99
  2. package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +2 -1
  3. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +1 -1
  4. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +49 -19
  5. package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +1 -0
  6. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +10 -71
  7. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +408 -376
  8. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +2 -2
  9. package/dist/cjs/components/Variables/variable-model.js +24 -22
  10. package/dist/cjs/context/ProjectStoreProvider.js +7 -4
  11. package/dist/cjs/context/ValidationProvider.js +69 -0
  12. package/dist/cjs/context/index.js +1 -0
  13. package/dist/cjs/index.js +0 -1
  14. package/dist/cjs/runtime/QueryCountProvider.js +83 -0
  15. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +100 -0
  16. package/dist/cjs/runtime/TimeRangeProvider/index.js +2 -1
  17. package/dist/cjs/runtime/builtin-variables.js +1 -1
  18. package/dist/cjs/runtime/datasources.js +22 -13
  19. package/dist/cjs/runtime/index.js +3 -2
  20. package/dist/cjs/runtime/plugin-registry.js +33 -22
  21. package/dist/cjs/runtime/time-series-queries.js +3 -3
  22. package/dist/cjs/runtime/trace-queries.js +5 -1
  23. package/dist/cjs/runtime/{template-variables.js → variables.js} +19 -19
  24. package/dist/cjs/stories/shared-utils/decorators/{WithPluginSystemTemplateVariables.js → WithPluginSystemVariables.js} +8 -8
  25. package/dist/cjs/stories/shared-utils/decorators/index.js +2 -2
  26. package/dist/cjs/test/mock-data.js +25 -4
  27. package/dist/cjs/test/render.js +1 -9
  28. package/dist/cjs/test/test-plugins/bert/index.js +20 -19
  29. package/dist/cjs/utils/variables.js +23 -23
  30. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +2 -2
  31. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  32. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +71 -100
  33. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  34. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -3
  35. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  36. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +1 -1
  37. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +1 -1
  38. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  39. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +1 -1
  40. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  41. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +3 -1
  42. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  43. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +50 -20
  44. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  45. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
  46. package/dist/components/PluginKindSelect/PluginKindSelect.js +1 -0
  47. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  48. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -2
  49. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  50. package/dist/components/TimeRangeControls/TimeRangeControls.js +12 -70
  51. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  52. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  53. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +411 -379
  54. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  55. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +2 -2
  56. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  57. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  58. package/dist/components/Variables/variable-model.js +25 -23
  59. package/dist/components/Variables/variable-model.js.map +1 -1
  60. package/dist/context/ProjectStoreProvider.d.ts.map +1 -1
  61. package/dist/context/ProjectStoreProvider.js +7 -4
  62. package/dist/context/ProjectStoreProvider.js.map +1 -1
  63. package/dist/context/ValidationProvider.d.ts +19 -0
  64. package/dist/context/ValidationProvider.d.ts.map +1 -0
  65. package/dist/context/ValidationProvider.js +52 -0
  66. package/dist/context/ValidationProvider.js.map +1 -0
  67. package/dist/context/index.d.ts +1 -0
  68. package/dist/context/index.d.ts.map +1 -1
  69. package/dist/context/index.js +1 -0
  70. package/dist/context/index.js.map +1 -1
  71. package/dist/index.d.ts +0 -1
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +0 -1
  74. package/dist/index.js.map +1 -1
  75. package/dist/model/panels.d.ts +2 -2
  76. package/dist/model/panels.d.ts.map +1 -1
  77. package/dist/model/panels.js.map +1 -1
  78. package/dist/runtime/DataQueriesProvider/model.d.ts +1 -1
  79. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  80. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  81. package/dist/runtime/QueryCountProvider.d.ts +9 -0
  82. package/dist/runtime/QueryCountProvider.d.ts.map +1 -0
  83. package/dist/{validation/duration.js → runtime/QueryCountProvider.js} +13 -4
  84. package/dist/runtime/QueryCountProvider.js.map +1 -0
  85. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts +32 -0
  86. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts.map +1 -0
  87. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +82 -0
  88. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -0
  89. package/dist/runtime/TimeRangeProvider/index.d.ts +1 -0
  90. package/dist/runtime/TimeRangeProvider/index.d.ts.map +1 -1
  91. package/dist/runtime/TimeRangeProvider/index.js +2 -1
  92. package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
  93. package/dist/runtime/builtin-variables.d.ts +1 -1
  94. package/dist/runtime/builtin-variables.d.ts.map +1 -1
  95. package/dist/runtime/builtin-variables.js +1 -1
  96. package/dist/runtime/builtin-variables.js.map +1 -1
  97. package/dist/runtime/datasources.d.ts.map +1 -1
  98. package/dist/runtime/datasources.js +22 -13
  99. package/dist/runtime/datasources.js.map +1 -1
  100. package/dist/runtime/index.d.ts +2 -1
  101. package/dist/runtime/index.d.ts.map +1 -1
  102. package/dist/runtime/index.js +3 -2
  103. package/dist/runtime/index.js.map +1 -1
  104. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  105. package/dist/runtime/plugin-registry.js +33 -22
  106. package/dist/runtime/plugin-registry.js.map +1 -1
  107. package/dist/runtime/time-series-queries.d.ts +2 -2
  108. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  109. package/dist/runtime/time-series-queries.js +3 -3
  110. package/dist/runtime/time-series-queries.js.map +1 -1
  111. package/dist/runtime/trace-queries.d.ts.map +1 -1
  112. package/dist/runtime/trace-queries.js +5 -1
  113. package/dist/runtime/trace-queries.js.map +1 -1
  114. package/dist/runtime/{template-variables.d.ts → variables.d.ts} +4 -4
  115. package/dist/runtime/variables.d.ts.map +1 -0
  116. package/dist/runtime/{template-variables.js → variables.js} +18 -17
  117. package/dist/runtime/variables.js.map +1 -0
  118. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts +12 -0
  119. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts.map +1 -0
  120. package/dist/stories/shared-utils/decorators/{WithPluginSystemTemplateVariables.js → WithPluginSystemVariables.js} +9 -9
  121. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +1 -0
  122. package/dist/stories/shared-utils/decorators/index.d.ts +1 -1
  123. package/dist/stories/shared-utils/decorators/index.d.ts.map +1 -1
  124. package/dist/stories/shared-utils/decorators/index.js +2 -2
  125. package/dist/stories/shared-utils/decorators/index.js.map +1 -1
  126. package/dist/test/mock-data.d.ts.map +1 -1
  127. package/dist/test/mock-data.js +25 -4
  128. package/dist/test/mock-data.js.map +1 -1
  129. package/dist/test/render.d.ts.map +1 -1
  130. package/dist/test/render.js +1 -9
  131. package/dist/test/render.js.map +1 -1
  132. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  133. package/dist/test/test-plugins/bert/index.js +20 -19
  134. package/dist/test/test-plugins/bert/index.js.map +1 -1
  135. package/dist/utils/variables.d.ts +4 -4
  136. package/dist/utils/variables.d.ts.map +1 -1
  137. package/dist/utils/variables.js +18 -18
  138. package/dist/utils/variables.js.map +1 -1
  139. package/package.json +5 -5
  140. package/dist/cjs/validation/datasource.js +0 -30
  141. package/dist/cjs/validation/duration.js +0 -25
  142. package/dist/cjs/validation/index.js +0 -34
  143. package/dist/cjs/validation/resource.js +0 -24
  144. package/dist/cjs/validation/role.js +0 -86
  145. package/dist/cjs/validation/rolebinding.js +0 -55
  146. package/dist/cjs/validation/secret.js +0 -176
  147. package/dist/cjs/validation/user.js +0 -46
  148. package/dist/cjs/validation/variable.js +0 -48
  149. package/dist/runtime/template-variables.d.ts.map +0 -1
  150. package/dist/runtime/template-variables.js.map +0 -1
  151. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.d.ts +0 -12
  152. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.d.ts.map +0 -1
  153. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js.map +0 -1
  154. package/dist/validation/datasource.d.ts +0 -19
  155. package/dist/validation/datasource.d.ts.map +0 -1
  156. package/dist/validation/datasource.js +0 -22
  157. package/dist/validation/datasource.js.map +0 -1
  158. package/dist/validation/duration.d.ts +0 -3
  159. package/dist/validation/duration.d.ts.map +0 -1
  160. package/dist/validation/duration.js.map +0 -1
  161. package/dist/validation/index.d.ts +0 -6
  162. package/dist/validation/index.d.ts.map +0 -1
  163. package/dist/validation/index.js +0 -19
  164. package/dist/validation/index.js.map +0 -1
  165. package/dist/validation/resource.d.ts +0 -3
  166. package/dist/validation/resource.d.ts.map +0 -1
  167. package/dist/validation/resource.js +0 -16
  168. package/dist/validation/resource.js.map +0 -1
  169. package/dist/validation/role.d.ts +0 -228
  170. package/dist/validation/role.d.ts.map +0 -1
  171. package/dist/validation/role.js +0 -67
  172. package/dist/validation/role.js.map +0 -1
  173. package/dist/validation/rolebinding.d.ts +0 -137
  174. package/dist/validation/rolebinding.d.ts.map +0 -1
  175. package/dist/validation/rolebinding.js +0 -47
  176. package/dist/validation/rolebinding.js.map +0 -1
  177. package/dist/validation/secret.d.ts +0 -964
  178. package/dist/validation/secret.d.ts.map +0 -1
  179. package/dist/validation/secret.js +0 -157
  180. package/dist/validation/secret.js.map +0 -1
  181. package/dist/validation/user.d.ts +0 -93
  182. package/dist/validation/user.d.ts.map +0 -1
  183. package/dist/validation/user.js +0 -38
  184. package/dist/validation/user.js.map +0 -1
  185. package/dist/validation/variable.d.ts +0 -96
  186. package/dist/validation/variable.d.ts.map +0 -1
  187. package/dist/validation/variable.js +0 -40
  188. package/dist/validation/variable.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/utils/variables.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,CAgB9F;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,aAAa,UAc1G;AAWD;;GAEG;AACH,eAAO,MAAM,sBAAsB,SAAU,MAAM,aAkBlD,CAAC"}
1
+ {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/utils/variables.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,CAgBtF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,UAc1F;AAWD;;GAEG;AACH,eAAO,MAAM,cAAc,SAAU,MAAM,aAkB1C,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 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
@@ -10,8 +10,8 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- export function replaceTemplateVariables(text, variableState) {
14
- const variables = parseTemplateVariables(text);
13
+ export function replaceVariables(text, variableState) {
14
+ const variables = parseVariables(text);
15
15
  let finalText = text;
16
16
  variables// Sorting variables by their length.
17
17
  // In order to not have a variable name have contained in another variable name.
@@ -19,36 +19,36 @@ export function replaceTemplateVariables(text, variableState) {
19
19
  .sort((a, b)=>b.length - a.length).forEach((v)=>{
20
20
  const variable = variableState[v];
21
21
  if (variable && (variable === null || variable === void 0 ? void 0 : variable.value)) {
22
- finalText = replaceTemplateVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
22
+ finalText = replaceVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
23
23
  }
24
24
  });
25
25
  return finalText;
26
26
  }
27
- export function replaceTemplateVariable(text, varName, templateVariableValue) {
28
- const variableTemplate = '$' + varName;
29
- const bracketsVariableTemplate = '${' + varName + '}';
27
+ export function replaceVariable(text, varName, variableValue) {
28
+ const variableSyntax = '$' + varName;
29
+ const alternativeVariableSyntax = '${' + varName + '}';
30
30
  let replaceString = '';
31
- if (Array.isArray(templateVariableValue)) {
32
- replaceString = `(${templateVariableValue.join('|')})`; // regex style
31
+ if (Array.isArray(variableValue)) {
32
+ replaceString = `(${variableValue.join('|')})`; // regex style
33
33
  }
34
- if (typeof templateVariableValue === 'string') {
35
- replaceString = templateVariableValue;
34
+ if (typeof variableValue === 'string') {
35
+ replaceString = variableValue;
36
36
  }
37
- text = text.replaceAll(variableTemplate, replaceString);
38
- return text.replaceAll(bracketsVariableTemplate, replaceString);
37
+ text = text.replaceAll(variableSyntax, replaceString);
38
+ return text.replaceAll(alternativeVariableSyntax, replaceString);
39
39
  }
40
- // This regular expression is designed to identify variable references in a template string.
40
+ // This regular expression is designed to identify variable references in a string.
41
41
  // It supports two formats for referencing variables:
42
42
  // 1. $variableName - This is a simpler format, and the regular expression captures the variable name (\w+ matches one or more word characters).
43
43
  // 2. ${variableName} - This is a more complex format and the regular expression captures the variable name (\w+ matches one or more word characters) in the curly braces.
44
44
  // 3. [COMING SOON] ${variableName:value} - This is a more complex format that allows specifying a format function as well.
45
45
  // TODO: Fix this lint error
46
46
  // eslint-disable-next-line no-useless-escape
47
- const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
47
+ const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
48
48
  /**
49
- * Returns a list of template variables
50
- */ export const parseTemplateVariables = (text)=>{
51
- const regex = TEMPLATE_VARIABLE_REGEX;
49
+ * Returns a list of variables
50
+ */ export const parseVariables = (text)=>{
51
+ const regex = VARIABLE_REGEX;
52
52
  const matches = new Set();
53
53
  let match;
54
54
  while((match = regex.exec(text)) !== null){
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/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 { VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\n\nexport function replaceTemplateVariables(text: string, variableState: VariableStateMap): string {\n const variables = parseTemplateVariables(text);\n let finalText = text;\n variables\n // Sorting variables by their length.\n // In order to not have a variable name have contained in another variable name.\n // i.e.: $__range replacing $__range_ms => '3600_ms' instead of '3600000'\n .sort((a, b) => b.length - a.length)\n .forEach((v) => {\n const variable = variableState[v];\n if (variable && variable?.value) {\n finalText = replaceTemplateVariable(finalText, v, variable?.value);\n }\n });\n\n return finalText;\n}\n\nexport function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue) {\n const variableTemplate = '$' + varName;\n const bracketsVariableTemplate = '${' + varName + '}';\n\n let replaceString = '';\n if (Array.isArray(templateVariableValue)) {\n replaceString = `(${templateVariableValue.join('|')})`; // regex style\n }\n if (typeof templateVariableValue === 'string') {\n replaceString = templateVariableValue;\n }\n\n text = text.replaceAll(variableTemplate, replaceString);\n return text.replaceAll(bracketsVariableTemplate, replaceString);\n}\n\n// This regular expression is designed to identify variable references in a template string.\n// It supports two formats for referencing variables:\n// 1. $variableName - This is a simpler format, and the regular expression captures the variable name (\\w+ matches one or more word characters).\n// 2. ${variableName} - This is a more complex format and the regular expression captures the variable name (\\w+ matches one or more word characters) in the curly braces.\n// 3. [COMING SOON] ${variableName:value} - This is a more complex format that allows specifying a format function as well.\n// TODO: Fix this lint error\n// eslint-disable-next-line no-useless-escape\nconst TEMPLATE_VARIABLE_REGEX = /\\$(\\w+)|\\${(\\w+)(?:\\.([^:^\\}]+))?(?::([^\\}]+))?}/gm;\n\n/**\n * Returns a list of template variables\n */\nexport const parseTemplateVariables = (text: string) => {\n const regex = TEMPLATE_VARIABLE_REGEX;\n const matches = new Set<string>();\n let match;\n\n while ((match = regex.exec(text)) !== null) {\n if (match) {\n if (match[1]) {\n // \\$(\\w+)\\\n matches.add(match[1]);\n } else if (match[2]) {\n // \\${(\\w+)}\\\n matches.add(match[2]);\n }\n }\n }\n // return unique matches\n return Array.from(matches.values());\n};\n"],"names":["replaceTemplateVariables","text","variableState","variables","parseTemplateVariables","finalText","sort","a","b","length","forEach","v","variable","value","replaceTemplateVariable","varName","templateVariableValue","variableTemplate","bracketsVariableTemplate","replaceString","Array","isArray","join","replaceAll","TEMPLATE_VARIABLE_REGEX","regex","matches","Set","match","exec","add","from","values"],"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;AAKjC,OAAO,SAASA,yBAAyBC,IAAY,EAAEC,aAA+B;IACpF,MAAMC,YAAYC,uBAAuBH;IACzC,IAAII,YAAYJ;IAChBE,SACE,qCAAqC;IACrC,gFAAgF;IAChF,yEAAyE;KACxEG,IAAI,CAAC,CAACC,GAAGC,IAAMA,EAAEC,MAAM,GAAGF,EAAEE,MAAM,EAClCC,OAAO,CAAC,CAACC;QACR,MAAMC,WAAWV,aAAa,CAACS,EAAE;QACjC,IAAIC,aAAYA,qBAAAA,+BAAAA,SAAUC,KAAK,GAAE;YAC/BR,YAAYS,wBAAwBT,WAAWM,GAAGC,qBAAAA,+BAAAA,SAAUC,KAAK;QACnE;IACF;IAEF,OAAOR;AACT;AAEA,OAAO,SAASS,wBAAwBb,IAAY,EAAEc,OAAe,EAAEC,qBAAoC;IACzG,MAAMC,mBAAmB,MAAMF;IAC/B,MAAMG,2BAA2B,OAAOH,UAAU;IAElD,IAAII,gBAAgB;IACpB,IAAIC,MAAMC,OAAO,CAACL,wBAAwB;QACxCG,gBAAgB,CAAC,CAAC,EAAEH,sBAAsBM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc;IACxE;IACA,IAAI,OAAON,0BAA0B,UAAU;QAC7CG,gBAAgBH;IAClB;IAEAf,OAAOA,KAAKsB,UAAU,CAACN,kBAAkBE;IACzC,OAAOlB,KAAKsB,UAAU,CAACL,0BAA0BC;AACnD;AAEA,4FAA4F;AAC5F,qDAAqD;AACrD,gJAAgJ;AAChJ,0KAA0K;AAC1K,2HAA2H;AAC3H,4BAA4B;AAC5B,6CAA6C;AAC7C,MAAMK,0BAA0B;AAEhC;;CAEC,GACD,OAAO,MAAMpB,yBAAyB,CAACH;IACrC,MAAMwB,QAAQD;IACd,MAAME,UAAU,IAAIC;IACpB,IAAIC;IAEJ,MAAO,AAACA,CAAAA,QAAQH,MAAMI,IAAI,CAAC5B,KAAI,MAAO,KAAM;QAC1C,IAAI2B,OAAO;YACT,IAAIA,KAAK,CAAC,EAAE,EAAE;gBACZ,WAAW;gBACXF,QAAQI,GAAG,CAACF,KAAK,CAAC,EAAE;YACtB,OAAO,IAAIA,KAAK,CAAC,EAAE,EAAE;gBACnB,aAAa;gBACbF,QAAQI,GAAG,CAACF,KAAK,CAAC,EAAE;YACtB;QACF;IACF;IACA,wBAAwB;IACxB,OAAOR,MAAMW,IAAI,CAACL,QAAQM,MAAM;AAClC,EAAE"}
1
+ {"version":3,"sources":["../../src/utils/variables.ts"],"sourcesContent":["// Copyright 2024 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 { VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\n\nexport function replaceVariables(text: string, variableState: VariableStateMap): string {\n const variables = parseVariables(text);\n let finalText = text;\n variables\n // Sorting variables by their length.\n // In order to not have a variable name have contained in another variable name.\n // i.e.: $__range replacing $__range_ms => '3600_ms' instead of '3600000'\n .sort((a, b) => b.length - a.length)\n .forEach((v) => {\n const variable = variableState[v];\n if (variable && variable?.value) {\n finalText = replaceVariable(finalText, v, variable?.value);\n }\n });\n\n return finalText;\n}\n\nexport function replaceVariable(text: string, varName: string, variableValue: VariableValue) {\n const variableSyntax = '$' + varName;\n const alternativeVariableSyntax = '${' + varName + '}';\n\n let replaceString = '';\n if (Array.isArray(variableValue)) {\n replaceString = `(${variableValue.join('|')})`; // regex style\n }\n if (typeof variableValue === 'string') {\n replaceString = variableValue;\n }\n\n text = text.replaceAll(variableSyntax, replaceString);\n return text.replaceAll(alternativeVariableSyntax, replaceString);\n}\n\n// This regular expression is designed to identify variable references in a string.\n// It supports two formats for referencing variables:\n// 1. $variableName - This is a simpler format, and the regular expression captures the variable name (\\w+ matches one or more word characters).\n// 2. ${variableName} - This is a more complex format and the regular expression captures the variable name (\\w+ matches one or more word characters) in the curly braces.\n// 3. [COMING SOON] ${variableName:value} - This is a more complex format that allows specifying a format function as well.\n// TODO: Fix this lint error\n// eslint-disable-next-line no-useless-escape\nconst VARIABLE_REGEX = /\\$(\\w+)|\\${(\\w+)(?:\\.([^:^\\}]+))?(?::([^\\}]+))?}/gm;\n\n/**\n * Returns a list of variables\n */\nexport const parseVariables = (text: string) => {\n const regex = VARIABLE_REGEX;\n const matches = new Set<string>();\n let match;\n\n while ((match = regex.exec(text)) !== null) {\n if (match) {\n if (match[1]) {\n // \\$(\\w+)\\\n matches.add(match[1]);\n } else if (match[2]) {\n // \\${(\\w+)}\\\n matches.add(match[2]);\n }\n }\n }\n // return unique matches\n return Array.from(matches.values());\n};\n"],"names":["replaceVariables","text","variableState","variables","parseVariables","finalText","sort","a","b","length","forEach","v","variable","value","replaceVariable","varName","variableValue","variableSyntax","alternativeVariableSyntax","replaceString","Array","isArray","join","replaceAll","VARIABLE_REGEX","regex","matches","Set","match","exec","add","from","values"],"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;AAKjC,OAAO,SAASA,iBAAiBC,IAAY,EAAEC,aAA+B;IAC5E,MAAMC,YAAYC,eAAeH;IACjC,IAAII,YAAYJ;IAChBE,SACE,qCAAqC;IACrC,gFAAgF;IAChF,yEAAyE;KACxEG,IAAI,CAAC,CAACC,GAAGC,IAAMA,EAAEC,MAAM,GAAGF,EAAEE,MAAM,EAClCC,OAAO,CAAC,CAACC;QACR,MAAMC,WAAWV,aAAa,CAACS,EAAE;QACjC,IAAIC,aAAYA,qBAAAA,+BAAAA,SAAUC,KAAK,GAAE;YAC/BR,YAAYS,gBAAgBT,WAAWM,GAAGC,qBAAAA,+BAAAA,SAAUC,KAAK;QAC3D;IACF;IAEF,OAAOR;AACT;AAEA,OAAO,SAASS,gBAAgBb,IAAY,EAAEc,OAAe,EAAEC,aAA4B;IACzF,MAAMC,iBAAiB,MAAMF;IAC7B,MAAMG,4BAA4B,OAAOH,UAAU;IAEnD,IAAII,gBAAgB;IACpB,IAAIC,MAAMC,OAAO,CAACL,gBAAgB;QAChCG,gBAAgB,CAAC,CAAC,EAAEH,cAAcM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc;IAChE;IACA,IAAI,OAAON,kBAAkB,UAAU;QACrCG,gBAAgBH;IAClB;IAEAf,OAAOA,KAAKsB,UAAU,CAACN,gBAAgBE;IACvC,OAAOlB,KAAKsB,UAAU,CAACL,2BAA2BC;AACpD;AAEA,mFAAmF;AACnF,qDAAqD;AACrD,gJAAgJ;AAChJ,0KAA0K;AAC1K,2HAA2H;AAC3H,4BAA4B;AAC5B,6CAA6C;AAC7C,MAAMK,iBAAiB;AAEvB;;CAEC,GACD,OAAO,MAAMpB,iBAAiB,CAACH;IAC7B,MAAMwB,QAAQD;IACd,MAAME,UAAU,IAAIC;IACpB,IAAIC;IAEJ,MAAO,AAACA,CAAAA,QAAQH,MAAMI,IAAI,CAAC5B,KAAI,MAAO,KAAM;QAC1C,IAAI2B,OAAO;YACT,IAAIA,KAAK,CAAC,EAAE,EAAE;gBACZ,WAAW;gBACXF,QAAQI,GAAG,CAACF,KAAK,CAAC,EAAE;YACtB,OAAO,IAAIA,KAAK,CAAC,EAAE,EAAE;gBACnB,aAAa;gBACbF,QAAQI,GAAG,CAACF,KAAK,CAAC,EAAE;YACtB;QACF;IACF;IACA,wBAAwB;IACxB,OAAOR,MAAMW,IAAI,CAACL,QAAQM,MAAM;AAClC,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/plugin-system",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "description": "The plugin feature in Pereses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -28,8 +28,8 @@
28
28
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
29
29
  },
30
30
  "dependencies": {
31
- "@perses-dev/components": "0.46.0",
32
- "@perses-dev/core": "0.46.0",
31
+ "@perses-dev/components": "0.47.0",
32
+ "@perses-dev/core": "0.47.0",
33
33
  "date-fns": "^2.30.0",
34
34
  "immer": "^9.0.15",
35
35
  "react-hook-form": "^7.46.1",
@@ -38,10 +38,10 @@
38
38
  "zod": "^3.22.2"
39
39
  },
40
40
  "devDependencies": {
41
- "@perses-dev/storybook": "0.46.0"
41
+ "@perses-dev/storybook": "0.47.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@mui/material": "^5.10.0",
44
+ "@mui/material": "^5.15.20",
45
45
  "@tanstack/react-query": "^4.7.1",
46
46
  "react": "^17.0.2 || ^18.0.0",
47
47
  "react-dom": "^17.0.2 || ^18.0.0"
@@ -1,30 +0,0 @@
1
- // Copyright 2023 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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- Object.defineProperty(exports, "datasourceEditValidationSchema", {
18
- enumerable: true,
19
- get: function() {
20
- return datasourceEditValidationSchema;
21
- }
22
- });
23
- const _zod = require("zod");
24
- const _resource = require("./resource");
25
- const datasourceEditValidationSchema = _zod.z.object({
26
- name: _resource.resourceIdValidationSchema,
27
- title: _zod.z.string().optional(),
28
- description: _zod.z.string().optional(),
29
- default: _zod.z.boolean()
30
- });
@@ -1,25 +0,0 @@
1
- // Copyright 2024 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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- Object.defineProperty(exports, "durationValidationSchema", {
18
- enumerable: true,
19
- get: function() {
20
- return durationValidationSchema;
21
- }
22
- });
23
- const _core = require("@perses-dev/core");
24
- const _zod = require("zod");
25
- const durationValidationSchema = _zod.z.string().nonempty('Required').regex(_core.DURATION_REGEX, 'Must be a valid duration string');
@@ -1,34 +0,0 @@
1
- // Copyright 2023 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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- _export_star(require("./datasource"), exports);
18
- _export_star(require("./duration"), exports);
19
- _export_star(require("./resource"), exports);
20
- _export_star(require("./secret"), exports);
21
- _export_star(require("./variable"), exports);
22
- function _export_star(from, to) {
23
- Object.keys(from).forEach(function(k) {
24
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
25
- Object.defineProperty(to, k, {
26
- enumerable: true,
27
- get: function() {
28
- return from[k];
29
- }
30
- });
31
- }
32
- });
33
- return from;
34
- }
@@ -1,24 +0,0 @@
1
- // Copyright 2023 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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- Object.defineProperty(exports, "resourceIdValidationSchema", {
18
- enumerable: true,
19
- get: function() {
20
- return resourceIdValidationSchema;
21
- }
22
- });
23
- const _zod = require("zod");
24
- const resourceIdValidationSchema = _zod.z.string().min(1, 'Required').max(75, 'Must be 75 or fewer characters long').regex(/^[a-zA-Z0-9_.-]+$/, 'Must only contains alphanumerical characters and special characters _ . -');
@@ -1,86 +0,0 @@
1
- // Copyright 2023 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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- globalRoleValidationSchema: function() {
25
- return globalRoleValidationSchema;
26
- },
27
- roleValidationSchema: function() {
28
- return roleValidationSchema;
29
- },
30
- rolesEditorValidationSchema: function() {
31
- return rolesEditorValidationSchema;
32
- }
33
- });
34
- const _zod = require("zod");
35
- const _resource = require("./resource");
36
- const permissionValidationSchema = _zod.z.object({
37
- // TODO: use SCOPE & ACTIONS constants
38
- actions: _zod.z.array(_zod.z.enum([
39
- '*',
40
- 'create',
41
- 'read',
42
- 'update',
43
- 'delete'
44
- ])).nonempty('Must contains at least 1 action'),
45
- scopes: _zod.z.array(_zod.z.enum([
46
- '*',
47
- 'Dashboard',
48
- 'Datasource',
49
- 'EphemeralDashboard',
50
- 'Folder',
51
- 'GlobalDatasource',
52
- 'GlobalRole',
53
- 'GlobalRoleBinding',
54
- 'GlobalSecret',
55
- 'GlobalVariable',
56
- 'Project',
57
- 'Role',
58
- 'RoleBinding',
59
- 'Secret',
60
- 'User',
61
- 'Variable'
62
- ])).nonempty('Must contains at least 1 scope')
63
- });
64
- const roleValidationSchema = _zod.z.object({
65
- kind: _zod.z.literal('Role'),
66
- metadata: _zod.z.object({
67
- name: _resource.resourceIdValidationSchema,
68
- project: _resource.resourceIdValidationSchema
69
- }),
70
- spec: _zod.z.object({
71
- permissions: _zod.z.array(permissionValidationSchema)
72
- })
73
- });
74
- const globalRoleValidationSchema = _zod.z.object({
75
- kind: _zod.z.literal('GlobalRole'),
76
- metadata: _zod.z.object({
77
- name: _resource.resourceIdValidationSchema
78
- }),
79
- spec: _zod.z.object({
80
- permissions: _zod.z.array(permissionValidationSchema)
81
- })
82
- });
83
- const rolesEditorValidationSchema = _zod.z.discriminatedUnion('kind', [
84
- roleValidationSchema,
85
- globalRoleValidationSchema
86
- ]);
@@ -1,55 +0,0 @@
1
- // Copyright 2023 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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- Object.defineProperty(exports, "roleBindingsEditorValidationSchema", {
18
- enumerable: true,
19
- get: function() {
20
- return roleBindingsEditorValidationSchema;
21
- }
22
- });
23
- const _zod = require("zod");
24
- const _resource = require("./resource");
25
- const subjectValidationSchema = _zod.z.object({
26
- kind: _zod.z.enum([
27
- 'User'
28
- ]),
29
- name: _resource.resourceIdValidationSchema
30
- });
31
- const roleBindingValidationSchema = _zod.z.object({
32
- kind: _zod.z.literal('RoleBinding'),
33
- metadata: _zod.z.object({
34
- name: _resource.resourceIdValidationSchema,
35
- project: _resource.resourceIdValidationSchema
36
- }),
37
- spec: _zod.z.object({
38
- role: _resource.resourceIdValidationSchema,
39
- subjects: _zod.z.array(subjectValidationSchema).nonempty()
40
- })
41
- });
42
- const globalRoleBindingValidationSchema = _zod.z.object({
43
- kind: _zod.z.literal('GlobalRoleBinding'),
44
- metadata: _zod.z.object({
45
- name: _resource.resourceIdValidationSchema
46
- }),
47
- spec: _zod.z.object({
48
- role: _resource.resourceIdValidationSchema,
49
- subjects: _zod.z.array(subjectValidationSchema)
50
- })
51
- });
52
- const roleBindingsEditorValidationSchema = _zod.z.discriminatedUnion('kind', [
53
- roleBindingValidationSchema,
54
- globalRoleBindingValidationSchema
55
- ]);
@@ -1,176 +0,0 @@
1
- // Copyright 2023 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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- globalSecretValidationSchema: function() {
25
- return globalSecretValidationSchema;
26
- },
27
- secretValidationSchema: function() {
28
- return secretValidationSchema;
29
- },
30
- secretsEditorValidationSchema: function() {
31
- return secretsEditorValidationSchema;
32
- }
33
- });
34
- const _zod = require("zod");
35
- const _resource = require("./resource");
36
- const secretSpecSchema = _zod.z.object({
37
- basicAuth: _zod.z.object({
38
- username: _zod.z.string().min(1),
39
- password: _zod.z.string().optional(),
40
- passwordFile: _zod.z.string().optional()
41
- }).superRefine((val, ctx)=>{
42
- if (val.password && val.password.length > 0 && val.passwordFile && val.passwordFile.length > 0) {
43
- ctx.addIssue({
44
- code: _zod.z.ZodIssueCode.custom,
45
- message: 'Only one of the fields must be defined',
46
- path: [
47
- 'password'
48
- ]
49
- });
50
- ctx.addIssue({
51
- code: _zod.z.ZodIssueCode.custom,
52
- message: 'Only one of the fields must be defined',
53
- path: [
54
- 'passwordFile'
55
- ]
56
- });
57
- }
58
- }).optional(),
59
- authorization: _zod.z.object({
60
- type: _zod.z.string().optional(),
61
- credentials: _zod.z.string().optional(),
62
- credentialsFile: _zod.z.string().optional()
63
- }).superRefine((val, ctx)=>{
64
- if (val.credentials && val.credentials.length > 0 && val.credentialsFile && val.credentialsFile.length > 0) {
65
- ctx.addIssue({
66
- code: _zod.z.ZodIssueCode.custom,
67
- message: 'Only one of the fields must be defined',
68
- path: [
69
- 'credentials'
70
- ]
71
- });
72
- ctx.addIssue({
73
- code: _zod.z.ZodIssueCode.custom,
74
- message: 'Only one of the fields must be defined',
75
- path: [
76
- 'credentialsFile'
77
- ]
78
- });
79
- }
80
- }).optional(),
81
- tlsConfig: _zod.z.object({
82
- ca: _zod.z.string().optional(),
83
- cert: _zod.z.string().optional(),
84
- key: _zod.z.string().optional(),
85
- caFile: _zod.z.string().optional(),
86
- certFile: _zod.z.string().optional(),
87
- keyFile: _zod.z.string().optional(),
88
- serverName: _zod.z.string().optional(),
89
- insecureSkipVerify: _zod.z.boolean()
90
- }).superRefine((val, ctx)=>{
91
- if (val.ca && val.ca.length > 0 && val.caFile && val.caFile.length > 0) {
92
- ctx.addIssue({
93
- code: _zod.z.ZodIssueCode.custom,
94
- message: 'Only one of the fields must be defined',
95
- path: [
96
- 'ca'
97
- ]
98
- });
99
- ctx.addIssue({
100
- code: _zod.z.ZodIssueCode.custom,
101
- message: 'Only one of the fields must be defined',
102
- path: [
103
- 'caFile'
104
- ]
105
- });
106
- }
107
- if (val.cert && val.cert.length > 0 && val.certFile && val.certFile.length > 0) {
108
- ctx.addIssue({
109
- code: _zod.z.ZodIssueCode.custom,
110
- message: 'Only one of the fields must be defined',
111
- path: [
112
- 'cert'
113
- ]
114
- });
115
- ctx.addIssue({
116
- code: _zod.z.ZodIssueCode.custom,
117
- message: 'Only one of the fields must be defined',
118
- path: [
119
- 'certFile'
120
- ]
121
- });
122
- }
123
- if (val.key && val.key.length > 0 && val.keyFile && val.keyFile.length > 0) {
124
- ctx.addIssue({
125
- code: _zod.z.ZodIssueCode.custom,
126
- message: 'Only one of the fields must be defined',
127
- path: [
128
- 'key'
129
- ]
130
- });
131
- ctx.addIssue({
132
- code: _zod.z.ZodIssueCode.custom,
133
- message: 'Only one of the fields must be defined',
134
- path: [
135
- 'keyFile'
136
- ]
137
- });
138
- }
139
- }).optional()
140
- }).superRefine((val, ctx)=>{
141
- if (val.basicAuth && val.authorization) {
142
- ctx.addIssue({
143
- code: _zod.z.ZodIssueCode.custom,
144
- message: 'Only one of the fields must be defined',
145
- path: [
146
- 'basicAuth'
147
- ]
148
- });
149
- ctx.addIssue({
150
- code: _zod.z.ZodIssueCode.custom,
151
- message: 'Only one of the fields must be defined',
152
- path: [
153
- 'authorization'
154
- ]
155
- });
156
- }
157
- });
158
- const secretValidationSchema = _zod.z.object({
159
- kind: _zod.z.literal('Secret'),
160
- metadata: _zod.z.object({
161
- name: _resource.resourceIdValidationSchema,
162
- project: _resource.resourceIdValidationSchema
163
- }),
164
- spec: secretSpecSchema
165
- });
166
- const globalSecretValidationSchema = _zod.z.object({
167
- kind: _zod.z.literal('GlobalSecret'),
168
- metadata: _zod.z.object({
169
- name: _resource.resourceIdValidationSchema
170
- }),
171
- spec: secretSpecSchema
172
- });
173
- const secretsEditorValidationSchema = _zod.z.discriminatedUnion('kind', [
174
- secretValidationSchema,
175
- globalSecretValidationSchema
176
- ]);
@@ -1,46 +0,0 @@
1
- // Copyright 2023 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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- Object.defineProperty(exports, "userEditorValidationSchema", {
18
- enumerable: true,
19
- get: function() {
20
- return userEditorValidationSchema;
21
- }
22
- });
23
- const _zod = require("zod");
24
- const _resource = require("./resource");
25
- const nativeProviderSchema = _zod.z.object({
26
- password: _zod.z.string().optional()
27
- });
28
- const oauthProvidersSchema = _zod.z.object({
29
- issuer: _zod.z.string().optional(),
30
- email: _zod.z.string().optional(),
31
- subject: _zod.z.string().optional()
32
- });
33
- // TODO: handle exclusion native / oauth?
34
- const userSpecSchema = _zod.z.object({
35
- firstName: _zod.z.string().optional(),
36
- lastName: _zod.z.string().optional(),
37
- nativeProvider: nativeProviderSchema.optional(),
38
- oauthProviders: _zod.z.array(oauthProvidersSchema).optional()
39
- });
40
- const userEditorValidationSchema = _zod.z.object({
41
- kind: _zod.z.literal('User'),
42
- metadata: _zod.z.object({
43
- name: _resource.resourceIdValidationSchema
44
- }),
45
- spec: userSpecSchema
46
- });